|
@@ -1,7 +1,7 @@
|
1
|
1
|
import express, { Application, Request, Response } from 'express';
|
2
|
|
-import cors from 'cors';
|
3
|
2
|
import path from 'path';
|
4
|
3
|
import bodyParser from 'body-parser';
|
|
4
|
+import cors from 'cors';
|
5
|
5
|
|
6
|
6
|
import { errorHandler } from './src/middleware/ErrorHandler';
|
7
|
7
|
import keycloak from './src/middleware/Keycloak';
|
|
@@ -19,27 +19,29 @@ import './src/utils/Scheduler';
|
19
|
19
|
|
20
|
20
|
const app: Application = express();
|
21
|
21
|
|
22
|
|
-const allowedOrigins = [
|
23
|
|
- 'http://localhost:3006', // frontend local
|
24
|
|
- 'https://radar-dev.farmagitechs.co.id' // production domain
|
|
22
|
+const whitelist = [
|
|
23
|
+ "http://localhost:3006",
|
|
24
|
+ "https://radar-dev.farmagitechs.co.id"
|
25
|
25
|
];
|
26
|
26
|
|
27
|
|
-const corsOptions = {
|
28
|
|
- origin: allowedOrigins,
|
29
|
|
- methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
|
30
|
|
- allowedHeaders: ['Content-Type', 'Authorization'],
|
31
|
|
- credentials: true,
|
32
|
|
-};
|
|
27
|
+var corsOptions = {
|
|
28
|
+ origin: function (origin: any, callback: any) {
|
|
29
|
+ if (whitelist.indexOf(origin) !== -1) {
|
|
30
|
+ callback(null, true)
|
|
31
|
+ } else {
|
|
32
|
+ callback(new Error('Not allowed by CORS'))
|
|
33
|
+ }
|
|
34
|
+ }
|
|
35
|
+}
|
33
|
36
|
|
34
|
37
|
app.use(cors(corsOptions));
|
35
|
|
-app.options('*', cors(corsOptions));
|
|
38
|
+
|
36
|
39
|
app.use(bodyParser.json());
|
37
|
40
|
app.use(keycloak.middleware());
|
38
|
|
-app.use(express.json())
|
|
41
|
+app.use(express.json());
|
39
|
42
|
app.use('/storage/', express.static(path.join(__dirname, 'storage/')));
|
40
|
43
|
|
41
|
44
|
const apiV1 = express.Router();
|
42
|
|
-
|
43
|
45
|
apiV1.use('/province', provinceRoutes);
|
44
|
46
|
apiV1.use('/city', cityRoutes);
|
45
|
47
|
apiV1.use('/hospital', hospitalRoutes);
|
|
@@ -47,9 +49,8 @@ apiV1.use('/hospital-area', salesHospitalRoutes);
|
47
|
49
|
apiV1.use('/vendor', vendorRoutes);
|
48
|
50
|
apiV1.use('/area', areaRoutes);
|
49
|
51
|
apiV1.use('/category', CategoryRoutes);
|
50
|
|
-// apiV1.use('/vendor-sales', vendorSalesRoutes);
|
51
|
52
|
|
52
|
|
-app.get('/', (req: Request, res: Response) => {
|
|
53
|
+app.get('', (req: Request, res: Response) => {
|
53
|
54
|
res.send('Selamat Datang di API Radar Farmagitechs');
|
54
|
55
|
});
|
55
|
56
|
|
|
@@ -58,4 +59,4 @@ app.use(errorHandler);
|
58
|
59
|
|
59
|
60
|
app.listen(config.port, () => {
|
60
|
61
|
console.log(`Server started on port ${config.port}`);
|
61
|
|
-})
|
|
62
|
+});
|