-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
64 lines (61 loc) · 1.84 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// imports
const express = require("express");
const app = express();
const helmet = require("helmet");
const rateLimit = require("express-rate-limit");
const mongoSanatize = require("express-mongo-sanitize");
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100,
message: "limit crossed by your IP " // limit each IP to 100 requests per windowMs
});
const cookieParser=require("cookie-parser");
// apply to all requests
app.use(limiter);
app.use(helmet());
app.use(express.static("public"));
app.use(express.json());
// ("/api/plans/:id");
app.use(mongoSanatize());
app.use(cookieParser(),(req,res,next)=>{
// console.log(req.cookies.jwt);
next();
})
// view engine
app.set("view engine", "pug");
// views folder
app.set("views", "template");
const planRouter = require("./router/planRouter");
const userRouter = require("./router/userRouter");
const viewRouter = require("./router/viewRouter");
const diabetesRouter=require("./router/diabetesRouter");
app.use("/", viewRouter);
app.use("/api/user", userRouter);
//
// Middle ware
app.use("/api/plans", planRouter);
app.use("/api/forms", diabetesRouter);
// app.use("/signup")
// server
module.exports = app;
// const fs = require("fs");
// app.use(express());
// Middleware
// app.use("/",(req,res,next)=>{
// console.log("Hi from middleWare 👌👌");
// next();
// })
// handler function
// routes
// Routers=> incoming path => middlewares
// define
// app.get("/api/plans", getAllPlans);
// app.get("/api/user");
// app.get("/api/plans/:id", getPlan);
// app.get("/api/user/:id", getUser);
// app.post("/api/plans", createPlan);
// app.post("/api/user");
// app.patch("/api/plans/:id", updatePlan);
// app.patch("/api/user/:id", updateUser);
// app.delete("/api/plans/:id", deleteUser);
// app.delete("/api/user/:id", deletePlan);