-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
39 lines (33 loc) · 653 Bytes
/
Copy pathapp.js
File metadata and controls
39 lines (33 loc) · 653 Bytes
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
// app.js
const express = require("express");
const cors = require("cors");
const app = express();
/**
* Global middlewares
*/
app.use(cors()); // allow all origins
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
/**
* Health check (optional but useful)
*/
app.get("/", (req, res) => {
res.json({
status: true,
message: "Server is running"
});
});
/**
* API routes
*/
app.use("/api", require("./routes"));
/**
* 404 handler (important)
*/
app.use((req, res) => {
res.status(404).json({
status: false,
message: "API endpoint not found"
});
});
module.exports = app;