-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
34 lines (30 loc) · 1.23 KB
/
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
const express = require('express')
const app = express()
//mongodb+srv://adarsh:[email protected]/WebDev?retryWrites=true&w=majority
const mongoose = require('mongoose');
const remoteURI = `mongodb+srv://adarsh:[email protected]/WebDev?retryWrites=true&w=majority&ssl=true`
//const localUri = `mongodb://localhost:27017/whiteboard-02`
try {
mongoose.connect(remoteURI,
{useNewUrlParser: true, useUnifiedTopology: true},
() => console.log('connected to db'));
} catch (err) {
console.log('failed to connect to db')
}
app.use(function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers',
'Content-Type, X-Requested-With, Origin');
res.header('Access-Control-Allow-Methods',
'GET, POST, PUT, PATCH, DELETE, OPTIONS');
next();
});
// const demos =require('./controllers/demos-controller')
// demos(app)
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
require('./controllers/quizzes-controller')(app)
require('./controllers/questions-controller')(app)
require('./controllers/quiz-attempts-controller')(app)
app.listen(process.env.PORT || 5000);