-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (24 loc) · 723 Bytes
/
server.js
File metadata and controls
28 lines (24 loc) · 723 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
const express = require('express');
const bodyParser = require('body-parser');
const mongodb = require('./db/connect');
// Import the cors middleware
const cors = require('cors');
const port = process.env.PORT || 8080;
const app = express();
app
.use(bodyParser.json())
.use(cors({ origin: '*' }))
.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
next();
})
.use('/', require('./routes/index'));
mongodb.initDb((err) => {
if (err) {
console.log(err);
} else {
app.listen(port);
console.log(`Connected to DB and listening on ${port}`);
}
});