forked from CCT-JunITer/PV-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
28 lines (22 loc) · 872 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
// server.js is entry point
const express = require('express')
const MongoClient = require('mongodb').MongoClient
const bodyParser = require('body-parser')
const db = require('./database');
const app = express()
app.use((req, res, next) => {
// Website you wish to allow to connect for testing: localhost
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000')
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE')
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type')
next()
})
app.use(express.json())
const port = 8080
MongoClient.connect(db.url, (err, database) => {
if (err) return console.log(err)
require('./routes')(app, database.db("PV-DB"));
app.listen(port, () => {
console.log('We are live on ' + port + ' with DB: ' + db.url);
});
})