Skip to content

Commit b749fa0

Browse files
committed
handle options call
1 parent 2ef27c8 commit b749fa0

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

server/api/AdminAPI.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ const debugMode = Array.from(process.argv.map((arg) => arg.trim().toLowerCase())
44
const logger = require('../modules/Logger')(debugMode);
55
const eventManager = (require('../modules/singletons/EventManager.js')).instance;
66
const cors = require('cors');
7-
const { CONTENT_TYPE_VALIDATOR } = require('../config/globals');
7+
const { CONTENT_TYPE_VALIDATOR, CORS_OPTIONS} = require('../config/globals');
88

9-
router.use(cors(
10-
(process.env.NODE_ENV?.trim() === 'development'
11-
? {
12-
origin: '*',
13-
optionsSuccessStatus: 200
14-
}
15-
: {
16-
origin: 'http://localhost:3000',
17-
optionsSuccessStatus: 200
18-
})
19-
));
9+
const ADMIN_CORS_OPTIONS = process.env.NODE_ENV?.trim() === 'development'
10+
? {
11+
origin: '*',
12+
optionsSuccessStatus: 200
13+
}
14+
: {
15+
origin: 'http://localhost:3000',
16+
optionsSuccessStatus: 200
17+
};
18+
router.use(cors(ADMIN_CORS_OPTIONS));
2019

2120
router.post('/sockets/broadcast', (req, res, next) => {
2221
CONTENT_TYPE_VALIDATOR(req, res, next);
@@ -29,6 +28,8 @@ router.post('/sockets/broadcast', function (req, res) {
2928
res.status(201).send('Broadcasted message to all connected sockets: ' + req.body?.message);
3029
});
3130

31+
router.options('/games/state', cors(ADMIN_CORS_OPTIONS));
32+
3233
router.get('/games/state', async (req, res) => {
3334
const gamesArray = [];
3435
const keys = await eventManager.publisher.keys('*');

0 commit comments

Comments
 (0)