Skip to content

Commit ff0c7cd

Browse files
committed
feat:cors issue
1 parent 24d910b commit ff0c7cd

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

api-gateway/src/middleware/security.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const applySecurityMiddleware = (app: Application) => {
1212

1313
// Configure CORS properly
1414
app.use(cors({
15-
origin: [Service.CLIENT_URL, "https://welearning.online"],
15+
origin: true,
1616
methods: ["GET", "POST", "HEAD", "PUT", "PATCH", "DELETE", "OPTIONS"],
1717
credentials: true,
1818
allowedHeaders: ['Content-Type', 'Authorization', 'Cookie', 'Range', 'Accept', 'X-Requested-With'],

api-gateway/src/routes.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ export const routes = (app: Application) => {
4747
next();
4848
});
4949

50+
app.options('*', (req, res) => {
51+
res.status(204).end();
52+
});
53+
54+
app.get("/test-cors", (req: Request, res: Response) => {
55+
res.header("Access-Control-Allow-Origin", "https://v-learning-client-5r8j.vercel.app");
56+
res.header("Access-Control-Allow-Credentials", "true");
57+
res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
58+
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
59+
res.status(200).json({status: "CORS test successful"});
60+
});
61+
5062
app.get("/health", (req: Request, res: Response) => {
5163
res.status(200).json({ status: "api-gateway is running" });
5264
});

0 commit comments

Comments
 (0)