-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathapp.js
40 lines (27 loc) · 817 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
32
33
34
35
36
37
38
39
40
import express from 'express'
import bodyparser from 'body-parser'
import cors from 'cors'
import logger from 'morgan'
import { dbconnect } from './config/bd'
const app = express()
import dotenv from 'dotenv'
if (process.env.NODE_ENV !== 'production') {
dotenv.config({ path: './config/config.env' })
}
//don't show the log when it is test
if (process.env.NODE_ENV !== "test") {
app.use(logger("dev"));
}
app.use(bodyparser.json())
app.use(bodyparser.urlencoded({ extended: false }))
//To allow cross-origin requests
app.use(cors())
import bookRoute from './src/routers/book'
import { notFound } from './src/helpers/apiResponse'
app.use('/api', bookRoute)
app.all("*", (req, res) => {
return notFound(res, 'Page Not Found')
})
// DB connection
dbconnect(process.env.DB_URL)
export default app