mirror of
https://github.com/AlecM33/Werewolf.git
synced 2026-01-01 16:59:29 +01:00
handle options call
This commit is contained in:
@@ -4,19 +4,18 @@ const debugMode = Array.from(process.argv.map((arg) => arg.trim().toLowerCase())
|
||||
const logger = require('../modules/Logger')(debugMode);
|
||||
const eventManager = (require('../modules/singletons/EventManager.js')).instance;
|
||||
const cors = require('cors');
|
||||
const { CONTENT_TYPE_VALIDATOR } = require('../config/globals');
|
||||
const { CONTENT_TYPE_VALIDATOR, CORS_OPTIONS} = require('../config/globals');
|
||||
|
||||
router.use(cors(
|
||||
(process.env.NODE_ENV?.trim() === 'development'
|
||||
? {
|
||||
origin: '*',
|
||||
optionsSuccessStatus: 200
|
||||
}
|
||||
: {
|
||||
origin: 'http://localhost:3000',
|
||||
optionsSuccessStatus: 200
|
||||
})
|
||||
));
|
||||
const ADMIN_CORS_OPTIONS = process.env.NODE_ENV?.trim() === 'development'
|
||||
? {
|
||||
origin: '*',
|
||||
optionsSuccessStatus: 200
|
||||
}
|
||||
: {
|
||||
origin: 'http://localhost:3000',
|
||||
optionsSuccessStatus: 200
|
||||
};
|
||||
router.use(cors(ADMIN_CORS_OPTIONS));
|
||||
|
||||
router.post('/sockets/broadcast', (req, res, next) => {
|
||||
CONTENT_TYPE_VALIDATOR(req, res, next);
|
||||
@@ -29,6 +28,8 @@ router.post('/sockets/broadcast', function (req, res) {
|
||||
res.status(201).send('Broadcasted message to all connected sockets: ' + req.body?.message);
|
||||
});
|
||||
|
||||
router.options('/games/state', cors(ADMIN_CORS_OPTIONS));
|
||||
|
||||
router.get('/games/state', async (req, res) => {
|
||||
const gamesArray = [];
|
||||
const keys = await eventManager.publisher.keys('*');
|
||||
|
||||
Reference in New Issue
Block a user