-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (26 loc) · 770 Bytes
/
Copy pathserver.js
File metadata and controls
30 lines (26 loc) · 770 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
require('dotenv/config');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const bodyParser = require('body-parser');
const routes = require('./routes');
const cors = require('cors');
let whitelist = ['http://192.168.100.78','http://192.168.100.24','http://192.168.100.78','http://192.168.100.49', 'http://example2.com','http://localhost:3000']
let corsOptions = {
origin: function (origin, callback) {
if (whitelist.indexOf(origin) !== -1 || !origin) {
callback(null, true)
} else {
callback(new Error('Not allowed by CORS'))
}
}
}
app.use(cors(corsOptions))
app.use(
bodyParser.urlencoded({
extended: true,
})
);
app.use(bodyParser.json());
routes(app);
app.listen(port);