-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (49 loc) · 1.4 KB
/
index.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
const express = require("express");
const loggerMiddleWare = require("morgan");
const corsMiddleWare = require("cors");
const { PORT } = require("./config/constants");
const authRouter = require("./routers/auth");
const barbershopRouter = require("./routers/barbershops");
const mapRouter = require("./routers/map");
const authMiddleWare = require("./auth/middleware");
const app = express();
app.use(loggerMiddleWare("dev"));
const bodyParserMiddleWare = express.json();
app.use(bodyParserMiddleWare);
app.use(corsMiddleWare());
if (process.env.DELAY) {
app.use((req, res, next) => {
setTimeout(() => next(), parseInt(process.env.DELAY));
});
}
app.get("/", (req, res) => {
res.send("Hi from express");
});
app.post("/echo", (req, res) => {
res.json({
youPosted: {
...req.body,
},
});
});
app.post("/authorized_post_request", authMiddleWare, (req, res) => {
// accessing user that was added to req by the auth middleware
const user = req.user;
// don't send back the password hash
delete user.dataValues["password"];
res.json({
youPosted: {
...req.body,
},
userFoundWithToken: {
...user.dataValues,
},
});
});
app.use("/", authRouter);
app.use("/barbershops", barbershopRouter);
app.use("/map", mapRouter);
// Listen for connections on specified port (default is port 4000)
app.listen(PORT, () => {
console.log(`Listening on port: ${PORT}`);
});