-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (37 loc) · 1.17 KB
/
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
41
42
43
44
45
import express from "express";
import cors from "cors";
import hpp from "hpp";
import morgan from "morgan";
import xssClean from "xss-clean";
import { corsOptions, serverSideErrorHandler, notFoundErrorHandler, limiter } from "./lib/index.js";
import { seedRouter, authRouter, userRouter } from "./routes/index.js";
const app = express();
app.use(hpp());
app.use(xssClean());
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static("public"));
app.use(morgan(":method :url :status :res[content-length] - :response-time ms"));
// Routes declaration
app.use("/api/seed", seedRouter);
app.use("/api/auth", limiter, authRouter);
app.use("/api/users", userRouter);
// Home route
app.get("/", (req, res) => {
res.status(200).json({
statusCode: 200,
message: "Home route."
});
});
// Health route
app.get("/health", (req, res) => {
res.status(200).json({
status: "✅ ok",
uptime: process.uptime(), // Current uptime of the Node.js process
message: "🚀 API is healthy"
});
});
app.use("*", notFoundErrorHandler);
app.use(serverSideErrorHandler);
export default app;