Enhanced CORS configuration in SocketManager and added allowed origins to server settings in config.json.
Some checks reported warnings
farmcontrol/farmcontrol-ws/pipeline/head This commit is unstable
Some checks reported warnings
farmcontrol/farmcontrol-ws/pipeline/head This commit is unstable
This commit is contained in:
parent
ddf230a20a
commit
a955def849
@ -2,7 +2,8 @@
|
||||
"development": {
|
||||
"server": {
|
||||
"port": 9090,
|
||||
"logLevel": "trace"
|
||||
"logLevel": "trace",
|
||||
"corsOrigins": ["https://web.farmcontrol.app", "https://dev.tombutcher.work", "http://localhost:5173", "http://localhost:3000"]
|
||||
},
|
||||
"auth": {
|
||||
"enabled": true,
|
||||
|
||||
@ -21,11 +21,20 @@ export class SocketManager {
|
||||
this.templateManager = new TemplateManager(this);
|
||||
|
||||
// Use the provided HTTP server
|
||||
// Create Socket.IO server
|
||||
// Create Socket.IO server - CORS applies to HTTP long-polling transport
|
||||
const allowedOrigins = config.server.corsOrigins || ['*'];
|
||||
const io = new Server(server, {
|
||||
cors: {
|
||||
origin: config.server.corsOrigins || '*',
|
||||
methods: ['GET', 'POST']
|
||||
origin: (origin, callback) => {
|
||||
// Allow requests with no origin (e.g. same-origin, Postman, native apps)
|
||||
if (!origin) return callback(null, true);
|
||||
if (allowedOrigins.includes('*')) return callback(null, true);
|
||||
if (allowedOrigins.includes(origin)) return callback(null, origin);
|
||||
callback(new Error('CORS not allowed'));
|
||||
},
|
||||
methods: ['GET', 'POST'],
|
||||
credentials: true,
|
||||
allowedHeaders: ['Content-Type', 'Authorization']
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user