Browse Source

set up cors

pearlgw 3 weeks ago
parent
commit
efaa09a21f
1 changed files with 14 additions and 1 deletions
  1. 14 1
      index.ts

+ 14 - 1
index.ts

@@ -19,7 +19,20 @@ import './src/utils/Scheduler';
19 19
 
20 20
 const app: Application = express();
21 21
 
22
-app.use(cors());
22
+const allowedOrigins = [
23
+    'http://localhost:3006', // frontend local
24
+    'https://radar-dev.farmagitechs.co.id' // production domain
25
+];
26
+
27
+const corsOptions = {
28
+    origin: allowedOrigins,
29
+    methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
30
+    allowedHeaders: ['Content-Type', 'Authorization'],
31
+    credentials: true,
32
+};
33
+
34
+app.use(cors(corsOptions));
35
+app.options('*', cors(corsOptions));
23 36
 app.use(bodyParser.json());
24 37
 app.use(keycloak.middleware());
25 38
 app.use(express.json())