handle options call

This commit is contained in:
AlecM33
2025-12-29 15:09:37 -05:00
parent 2ef27c8248
commit b749fa0801

View File

@@ -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('*');