-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
43 lines (31 loc) · 840 Bytes
/
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
import dotenv from 'dotenv'
dotenv.config()
import express from 'express'
import helmet from 'helmet'
import cors from 'cors'
import morgan from 'morgan'
import routes from './routes/index.js'
import { initBreeInstance } from './jobs/index.js'
const app = express()
app.use(express.json())
app.use(helmet())
app.use(cors())
app.disable('x-powered-by')
app.use('/api/v1', routes)
initBreeInstance()
morgan('combined', {
skip: function (req, res) { return res.statusCode < 400 }
})
// custom 404
app.use((req, res, next) => {
res.status(404).send("Not found")
})
// custom error handler
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send('Internal server error')
})
const PORT = process.env.PORT || 8004
app.listen(PORT, () => {
console.log("Server is running on port: ", PORT)
})