-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
49 lines (42 loc) · 1.36 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
const port = process.env.PORT || 3001
require('dotenv').config()
const MONGODB_URI = process.env.ATLAS_URI
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
const mongoose = require('mongoose')
mongoose.connect(MONGODB_URI,
// 'mongodb://localhost:27017/econ-studio',
{
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
console.log('Connected to mongodb atlas successfully')
})
.catch(err => console.log(err))
const session = require('express-session')
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
// cookie: {secure: true}
}))
// configure CORS
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()
})
require('./controllers/quiz-controller')(app)
require('./controllers/question-controller')(app)
require('./controllers/quiz-attempt-controller')(app)
app.get("/", (req, res) => {
res.send("Hello, Econ-Studio")
})
app.listen(port, () => console.log(`Econ-Studio app listening on port ${port}!`))