-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (48 loc) · 1.21 KB
/
app.js
File metadata and controls
57 lines (48 loc) · 1.21 KB
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
49
50
51
52
53
54
55
56
57
require("dotenv").config();
const express = require("express");
const cors = require("cors");
const paymentRoutes = require("./src/routes/payment.routes");
const requestLogger = require("./src/middlewares/requestLogger");
const winstonLogger = require("./src/utils/logger");
const app = express();
const PORT = process.env.PORT || 3000;
app.use(
cors({
origin: "*",
methods: ["GET", "POST"],
}),
);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(requestLogger);
app.get("/", (req, res) => {
res.json({
status: true,
message: "Welcome to DEYM API",
endpoints: ["/api/payments"],
serverTime: new Date().toLocaleString("id-ID", {
timeZone: "Asia/Jakarta",
}),
});
});
app.use("/api/payments", paymentRoutes);
app.use((req, res) => {
res.status(404).json({
status: false,
message: "Not found",
});
});
app.use((err, req, res, next) => {
winstonLogger.error(err.message, {
stack: err.stack,
path: req.originalUrl,
method: req.method,
});
res.status(500).json({
status: false,
message: "Internal server error",
});
});
app.listen(PORT, () => {
winstonLogger.info(`Server running on http://localhost:${PORT}`);
});