-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
46 lines (32 loc) · 916 Bytes
/
server.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const express = require('express');
const session = require('express-session');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const PORT = process.env.PORT || 3030
const adminRouter = require('./controller/admin.js')
const dataRouter = require('./controller/data.js')
require('dotenv').config()
require('./db/db');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(express.json());
app.use(session({
secret: 'foodsafety',
resave: false,
saveUninitialized: false
}));
const corsOptions = {
origin: ['http://localhost:3000'],
credentials: true,
optionsSuccessStatus: 200
}
app.use(cors(corsOptions));
app.use('/admin', adminRouter);
app.use('/data', dataRouter);
app.get('/', (req, res) => {
res.send("welcome")
})
app.listen(PORT, (err) => {
console.log(err || `server listening on port ${PORT}`)
});