fix(cors): refine CORS handling for OPTIONS requests
- Updated CORS middleware to explicitly handle OPTIONS requests, ensuring proper preflight response and improving API request handling.
This commit is contained in:
@@ -83,7 +83,12 @@ const corsOptions = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
app.use(cors(corsOptions));
|
app.use(cors(corsOptions));
|
||||||
app.options('*', cors(corsOptions));
|
app.use((req, res, next) => {
|
||||||
|
if (req.method === 'OPTIONS') {
|
||||||
|
return cors(corsOptions)(req, res, next);
|
||||||
|
}
|
||||||
|
return next();
|
||||||
|
});
|
||||||
app.use(express.json()); // To handle JSON request bodies
|
app.use(express.json()); // To handle JSON request bodies
|
||||||
|
|
||||||
app.use('/api/chat', chatRouter);
|
app.use('/api/chat', chatRouter);
|
||||||
|
|||||||
Reference in New Issue
Block a user