@@ -4,19 +4,18 @@ const debugMode = Array.from(process.argv.map((arg) => arg.trim().toLowerCase())
44const logger = require ( '../modules/Logger' ) ( debugMode ) ;
55const eventManager = ( require ( '../modules/singletons/EventManager.js' ) ) . instance ;
66const 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
2120router . 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+
3233router . get ( '/games/state' , async ( req , res ) => {
3334 const gamesArray = [ ] ;
3435 const keys = await eventManager . publisher . keys ( '*' ) ;
0 commit comments