-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (45 loc) · 1.18 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
import express from "express";
import { json, urlencoded } from "body-parser";
import { check } from "express-validator";
import morgan from "morgan";
import { signUp } from "./utils/auth/signUp";
import { signIn } from "./utils/auth/signIn";
import { protect } from "./middleware/protectRoute";
import userRouter from "./resources/user/user.router";
import database from "./utils/db";
const app = express();
app.use(json());
app.use(urlencoded({ extended: true }));
app.use(morgan("dev"));
const PORT = process.env.PORT || 5000;
database().catch(err => console.log(err));
app.post(
"/signup",
[
check("email", "Please enter a valid email")
.isEmail()
.normalizeEmail(),
check(
"password",
"Please enter a password of 6 characters or more"
).isLength({ min: 6 }),
],
signUp
);
app.post(
"/signin",
[
check("email", "Email is required")
.isEmail()
.normalizeEmail(),
check("password", "Valid password is required")
.not()
.isEmpty()
.trim()
.escape(),
],
signIn
);
app.use("/api", protect);
app.use("/api/user", userRouter);
app.listen(PORT, () => console.log(`Listening at http://localhost:${PORT}`));