generated from tripleten-com/se_project_express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (32 loc) · 1.08 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
require("dotenv").config();
const express = require("express");
const mongoose = require("mongoose");
const { errors } = require("celebrate");
const cors = require("cors");
const helmet = require("helmet");
const routes = require("./routes");
const { createUser, login } = require("./controllers/users");
const errorHandler = require("./middlewares/errorHandler");
const { validateSignUp, validateLogIn } = require("./middlewares/validation");
const { requestLogger, errorLogger } = require("./middlewares/logger");
const { PORT = 3001 } = process.env;
const app = express();
mongoose.connect("mongodb://127.0.0.1:27017/wtwr_db");
app.disable("x-powered-by");
app.use(cors());
app.use(helmet());
app.use(express.json());
app.get("/crash-test", () => {
setTimeout(() => {
throw new Error("Server will crash now");
}, 0);
});
app.use(requestLogger);
app.post("/signup", validateSignUp, createUser);
app.post("/signin", validateLogIn, login);
app.use(routes);
app.use(errorLogger);
app.use(errors());
app.use(errorHandler);
app.listen(PORT, () => {});
console.log("App listening at PORT 3001");