Skip to content

Commit 6822fd0

Browse files
authored
added remote frontend url in app.js (#10)
1 parent 374863d commit 6822fd0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

server/app.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ require('dotenv').config();
44

55
const app = express();
66

7-
app.use(cors());
8-
app.use(express.json());
7+
const allowedOrigins = [
8+
'http://localhost:5173',
9+
'https://store-management-frontend-kq05.onrender.com/'
10+
];
11+
12+
app.use(cors({
13+
origin: (origin, callback) => {
14+
if (!origin || allowedOrigins.includes(origin)) {
15+
callback(null, true);
16+
} else {
17+
callback(new Error('Not allowed by CORS'));
18+
}
19+
},
20+
credentials: true
21+
})); app.use(express.json());
922

1023
app.get('/', (req, res) => {
11-
res.send('API is running...');
24+
res.send('API is running...');
1225
});
1326

1427
const authRoutes = require('./routes/authRoutes');

0 commit comments

Comments
 (0)