feat: add cors header
This commit is contained in:
@@ -39,8 +39,8 @@ export const io = new Server(server);
|
||||
*/
|
||||
export const browserPool = new BrowserPool();
|
||||
|
||||
app.use(bodyParser.json({ limit: '10mb' }))
|
||||
app.use(bodyParser.urlencoded({ extended: true, limit: '10mb', parameterLimit: 9000 }));
|
||||
// app.use(bodyParser.json({ limit: '10mb' }))
|
||||
// app.use(bodyParser.urlencoded({ extended: true, limit: '10mb', parameterLimit: 9000 }));
|
||||
// parse cookies - "cookie" is true in csrfProtection
|
||||
app.use(cookieParser())
|
||||
|
||||
@@ -90,7 +90,18 @@ app.get('/', function (req, res) {
|
||||
return res.send('Maxun server started 🚀');
|
||||
});
|
||||
|
||||
server.listen(SERVER_PORT, async () => {
|
||||
// Add CORS headers
|
||||
app.use((req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
||||
if (req.method === 'OPTIONS') {
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
server.listen(SERVER_PORT, '0.0.0.0', async () => {
|
||||
try {
|
||||
await connectDB();
|
||||
await syncDB();
|
||||
@@ -101,7 +112,6 @@ server.listen(SERVER_PORT, async () => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
process.on('SIGINT', () => {
|
||||
console.log('Main app shutting down...');
|
||||
if (!isProduction) {
|
||||
|
||||
Reference in New Issue
Block a user