Skip to content

Commit 6ac466c

Browse files
test(deployment)
1 parent 0eb73c3 commit 6ac466c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

backend/server.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ dotenv.config();
99
const app = express();
1010
const PORT = process.env.PORT || 8000;
1111

12-
const allowedOrigin = process.env.FRONTEND_URL || 'http://localhost:3000';
12+
const allowedOrigins = (process.env.FRONTEND_URL || 'http://localhost:3000')
13+
.split(',')
14+
.map(origin => origin.trim());
1315

16+
console.log(`[server.js]:${allowedOrigins}`)
1417
// Middleware
1518
app.use(cors({
16-
origin: allowedOrigin,
19+
origin: (origin, callback) => {
20+
// Allow requests with no origin (like mobile apps or curl requests)
21+
if (!origin || allowedOrigins.includes(origin)) {
22+
callback(null, true);
23+
} else {
24+
callback(new Error('Not allowed by CORS'));
25+
}
26+
},
1727
credentials: true,
1828
}));
1929
app.use(express.json());
@@ -68,7 +78,7 @@ app.use('*', (req, res) => {
6878
if (process.env.NODE_ENV !== 'test') {
6979
app.listen(PORT, () => {
7080
console.log(`🚀 GoPredict API Server running on port ${PORT}`);
71-
console.log(`✅ CORS enabled for origin: ${allowedOrigin}`);
81+
console.log(`✅ CORS enabled for origins: ${allowedOrigins.join(', ')}`);
7282
console.log(`📊 Health check: http://localhost:${PORT}/api/health`);
7383
console.log(`🔮 Prediction endpoint: http://localhost:${PORT}/api/predict`);
7484
});

0 commit comments

Comments
 (0)