Fix CORS: lock to specific origins

This commit is contained in:
Scott Scoble 2026-05-02 16:53:08 -07:00
parent 1bf747bf68
commit 28e3ce922b

View file

@ -9,7 +9,11 @@ const PORT = process.env.PORT || 3001;
app.use(express.json());
app.use(express.static(path.join(__dirname, '../frontend/public')));
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
const allowedOrigins = ['http://localhost:3000', 'https://wardrobeai.scoble.me'];
const origin = req.headers.origin;
if (allowedOrigins.includes(origin)) {
res.header('Access-Control-Allow-Origin', origin);
}
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
if (req.method === 'OPTIONS') {