forked from Ahaanv19/SD_Auto_Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (25 loc) · 916 Bytes
/
server.js
File metadata and controls
30 lines (25 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const express = require('express');
const cors = require('cors');
const app = express();
const port = 8103;
// Use the CORS middleware to allow requests from your frontend
app.use(cors({
origin: 'https://ahaanv19.github.io', // Replace with your actual frontend URL
credentials: true // Enable credentials
}));
// Custom middleware to set additional CORS headers
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', 'https://ahaanv19.github.io');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.setHeader('Access-Control-Allow-Credentials', 'true');
next();
});
// Define a route for the root URL
app.get('/', (req, res) => {
res.send('Hello, World!');
});
// Start the server
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});