-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
40 lines (32 loc) · 851 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
require("dotenv").config();
const express = require("express");
const morgan = require("morgan");
const router = require("./routes");
const cors = require("cors");
const app = express();
const { PORT } = process.env;
app.use(cors());
app.use(express.json());
app.use(morgan("dev"));
app.use(express.urlencoded({ extended: true }));
app.set("view engine", "ejs");
app.use(router);
app.use("/public/document", express.static("public/document"));
app.use((req, res, next) => {
return res.status(404).json({
status: false,
message: "Are you lost?",
});
});
// 500 handler
app.use((err, req, res, next) => {
console.log(err);
return res.status(500).json({
status: false,
message: err.message,
});
});
const server = app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
module.exports = server;