-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
53 lines (47 loc) · 1.33 KB
/
app.js
File metadata and controls
53 lines (47 loc) · 1.33 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
import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";
import userRouter from "./routes/user.routes.js";
import connectDb from "./db/index.js";
const app=express();
// app.use(morgan('combined'));
app.use(cors({
origin:process.env.CORS_ORIGIN,
credentials:true
}));
app.use(express.json({limit:"16kb"}));
app.use(express.urlencoded({extended:true,limit:"16kb"}));
app.use(express.static("public"));
app.use(cookieParser());
const port = process.env.PORT || 3001;
// // Debug: List all registered routes
// app._router.stack.forEach((middleware) => {
// if (middleware.route) {
// // routes registered directly on the app
// console.log(middleware.route);
// } else if (middleware.name === 'router') {
// // router middleware
// middleware.handle.stack.forEach((handler) => {
// if (handler.route) {
// console.log(handler.route);
// }
// });
// }
// });
app.use("/api/v1/users",userRouter);
connectDb()
// If database successfully got connected then we will listen
// to the port
.then(() => {
app.on("error", (err) => {
console.log("ERROR", err);
throw err;
});
app.listen(port, () => {
console.log(`App is listening to ${port}`);
});
})
.catch(() => {
console.log("It is not running");
});
export default app;