-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (33 loc) · 1.48 KB
/
Copy pathapp.js
File metadata and controls
44 lines (33 loc) · 1.48 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
import express from "express";
import { PORT } from "./config/env.js";
import userRouter from "./routes/users.routes.js";
import authRouter from "./routes/auth.routes.js";
import subscriptionRouter from "./routes/subscriptions.routes.js";
import connectToDatabase from "./database/mongodb.js";
import errorMiddleware from "./middlewares/error.middleware.js";
import cookieParser from "cookie-parser";
import arcjetMiddleware from "./middlewares/arcjet.middleware.js";
import workflowRouter from "./routes/workflow.routes.js";
const app = express();
//builtin middleware
app.use(express.json()); //parse the incoming request with JSON payloads
app.use(express.urlencoded({ extended: false })); //this help us to parse form data that is sent in the request body
app.use(cookieParser()); //parse the incoming cookies
app.use(arcjetMiddleware);
// /Use is middleware function in express to use the router object
app.use("/api/v1/auth", authRouter); //http://localhost:5000/api/v1/auth/sign-in
app.use("/api/v1/users", userRouter); //http://localhost:5000/api/v1/users
app.use("/api/v1/subscriptions", subscriptionRouter); //http://localhost:5000/api/v1/auth/subscriptions
app.use("/api/v1/workflows", workflowRouter);
//custom error handler
app.use(errorMiddleware);
app.get("/", (req, res) => {
res.send("Hello World");
});
app.listen(PORT, async () => {
console.log(
`Subscription tracker api is running on port http://localhost:${PORT}`
);
await connectToDatabase();
});
export default app;