🔧 Fix CORS: Allow all origins for development
- Simplified CORS configuration to allow all origins (*) - Removed origin restrictions for easier development - Fixed CORS preflight request handling - Now allows requests from any domain including 192.168.1.96
This commit is contained in:
17
server.js
17
server.js
@@ -48,6 +48,23 @@ const io = new Server(server, {
|
||||
// MIDDLEWARE SETUP
|
||||
// ============================================================================
|
||||
|
||||
// CORS Configuration - Allow all origins for development
|
||||
app.use((req, res, next) => {
|
||||
// Allow all origins
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, PATCH');
|
||||
res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, X-API-Key');
|
||||
res.setHeader('Access-Control-Max-Age', '86400'); // 24 hours
|
||||
|
||||
// Handle preflight requests
|
||||
if (req.method === 'OPTIONS') {
|
||||
res.status(200).end();
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
// Body Parser Middleware
|
||||
app.use(express.json({ limit: '10mb' }));
|
||||
app.use(express.urlencoded({ extended: true, limit: '10mb' }));
|
||||
|
||||
Reference in New Issue
Block a user