forked from muhislah/angkasa_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.35 KB
/
index.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
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const path = require("path");
const app = express();
const authRouter = require("./src/route/authRoute");
const helmet = require('helmet')
const morgan = require('morgan')
const ticketRouter = require('./src/route/tiketRoute');
const { response } = require("./src/helper/response");
const airlinesRouter = require("./src/route/airlines");
const orderTicketRouter = require("./src/route/orderedTicket");
const usersRouter = require("./src/route/usersRoute");
app.use(express.json())
app.use(cors())
app.use(morgan('dev'))
app.use(helmet())
app.use('/logo', express.static(path.join(__dirname, './upload')))
app.use("/auth", authRouter)
app.use("/users", usersRouter)
app.use('/ticket', ticketRouter)
app.use('/airlines', airlinesRouter)
app.use('/orderticket', orderTicketRouter)
app.use(express.urlencoded({ extended: false }));
app.use("/img", express.static(path.join(__dirname, "./upload")));
app.use((err, req, res, next) => {
const messError = err.message || 'internal server error'
const statusCode = err.status || 500
res.status(statusCode).json({
message: messError
})
})
app.use((req, res) => {
return response(res, [], 300, 'PAGE NOT FOUND')
})
app.listen(process.env.PORT || 5000, () => {
console.log('server running on port ' + process.env.PORT)
})