forked from threedevs/3dev-fullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (22 loc) · 977 Bytes
/
server.js
File metadata and controls
28 lines (22 loc) · 977 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 app = express()
const port = 1337
const bodyParser = require('body-parser')
require('dotenv').config()
const { userDoc } = require("./db/mongoose")
//cors settings, adapt to your needs in production
app.all('*', (req, res, next) => {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, content-type")
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS, PATCH')
res.header('Access-Control-Expose-Headers', 'Authorization')
res.header("Access-Control-Allow-Credentials", true)
next();
})
app.use(bodyParser.json({ limit: '50mb' }))
app.use(bodyParser.urlencoded({ extended: true }))
app.use('/api/users', require('./routers/users'));
app.use('/api/books', require('./routers/books'));
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})