-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
31 lines (26 loc) · 883 Bytes
/
app.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
require('dotenv').config()
const express = require('express')
const app = express()
const cors = require('cors')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
const gameRouter = require('./routes/gameRouter')
const mongoConf = process.env.MONGO_CONFIG_URL
mongoose
.connect(mongoConf, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false })
.then(() => {
console.log('Connected to DB!')
})
.catch(() => {
console.log(' Unable to connect to DB...')
})
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', 'http://localhost:9000')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next()
})
app.use('/api/game', gameRouter)
module.exports = app