|
@@ -20,19 +20,27 @@ import './src/utils/Scheduler';
|
20
|
20
|
const app: Application = express();
|
21
|
21
|
|
22
|
22
|
const allowedOrigins = [
|
23
|
|
- 'http://localhost:3006', // frontend local
|
24
|
|
- 'https://radar-dev.farmagitechs.co.id' // production domain
|
|
23
|
+ "http://localhost:3006", // frontend local
|
|
24
|
+ "https://radar-dev.farmagitechs.co.id" // production domain
|
25
|
25
|
];
|
26
|
26
|
|
27
|
27
|
const corsOptions = {
|
28
|
|
- origin: allowedOrigins,
|
29
|
|
- methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
30
|
|
- allowedHeaders: ['Content-Type', 'Authorization'],
|
|
28
|
+ origin: (origin: string | undefined, callback: (err: Error | null, allow?: boolean) => void) => {
|
|
29
|
+ if (!origin || allowedOrigins.includes(origin)) {
|
|
30
|
+ // allow requests tanpa Origin (misal Postman) & origin yg ada di daftar
|
|
31
|
+ callback(null, true);
|
|
32
|
+ } else {
|
|
33
|
+ callback(new Error("Not allowed by CORS"));
|
|
34
|
+ }
|
|
35
|
+ },
|
|
36
|
+ methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
|
|
37
|
+ allowedHeaders: ["Content-Type", "Authorization"],
|
31
|
38
|
credentials: true,
|
32
|
39
|
};
|
33
|
40
|
|
|
41
|
+// app.use(cors());
|
34
|
42
|
app.use(cors(corsOptions));
|
35
|
|
-app.options('*', cors(corsOptions));
|
|
43
|
+app.options(/(.*)/, cors(corsOptions));
|
36
|
44
|
app.use(bodyParser.json());
|
37
|
45
|
app.use(keycloak.middleware());
|
38
|
46
|
app.use(express.json())
|
|
@@ -47,9 +55,8 @@ apiV1.use('/hospital-area', salesHospitalRoutes);
|
47
|
55
|
apiV1.use('/vendor', vendorRoutes);
|
48
|
56
|
apiV1.use('/area', areaRoutes);
|
49
|
57
|
apiV1.use('/category', CategoryRoutes);
|
50
|
|
-// apiV1.use('/vendor-sales', vendorSalesRoutes);
|
51
|
58
|
|
52
|
|
-app.get('/', (req: Request, res: Response) => {
|
|
59
|
+app.get('', (req: Request, res: Response) => {
|
53
|
60
|
res.send('Selamat Datang di API Radar Farmagitechs');
|
54
|
61
|
});
|
55
|
62
|
|