-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (25 loc) · 934 Bytes
/
index.js
File metadata and controls
31 lines (25 loc) · 934 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
31
import express from 'express';
import cors from 'cors';
import algorithmRoutes from './routes/api.js';
const app = express();
// Configure CORS
const allowedOrigins = ['https://akdualgoritma.com'];
const corsOptions = {
origin: function (origin, callback) {
// Allow requests with no origin (like mobile apps or curl requests)
if (!origin) return callback(null, true);
if (allowedOrigins.indexOf(origin) === -1) {
const msg = 'The CORS policy for this site does not allow access from the specified Origin.';
return callback(new Error(msg), false);
}
return callback(null, true);
}
};
app.use(cors({ origin: 'https://akdualgoritma.com' }));
app.use(cors(corsOptions));
app.use(express.json());
app.use('/', algorithmRoutes);
const port = parseInt(process.env.PORT) || 8000;
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});