-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (66 loc) · 2.1 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// -- get the express module -- //
const express = require("express");
const server = express();
const upload = require("./Middlewares/multerMW");
const authRoute = require("./Routes/AuthRoute");
const childRoute = require("./Routes/childRoute");
const teachRoute = require("./Routes/teacherRoute");
const classRoute = require("./Routes/classRoute");
const dotenv = require("dotenv");
// -- get the mongoose module -- //
const mongoose = require("mongoose");
// -- get the PORT -- //
const PORT = process.env.PORT || 8080;
// -- connect to the database -- //
mongoose
.connect("mongodb://localhost:27017/nursery")
.then(() => {
// -- listen to the server -- //
console.log("connected to the database");
server.listen(PORT, () => {
console.log(`server is listening to port ${PORT}`);
});
})
.catch((err) => console.log(err));
dotenv.config();
// -- get the jwt module -- //
jwt = require("jsonwebtoken");
// -- Build The Server --//
// -- Settings -- //
server.use(express.json());
server.use(express.urlencoded({ extended: false }));
server.use(upload.single("image"));
// -- Routes -- //
// -- Authuntication -- // Login, Change Password -- //
server.use(authRoute);
// -- Children -- //
server.use(childRoute);
// -- Teachers -- //
server.use(teachRoute);
// -- Class -- //
server.use(classRoute);
// server.post("/teachers", (req, res, next) => {
// res.status(201).json({ data: {}, message: "create teacher" });
// });
// -- Admin -- //
// const adminRoute = require("./Routes/admingRoute");
// server.use(adminRoute);
// -- Upload -- //
// server.post("/upload", (req, res, next) => {
// res.status(201).json({ data: {}, message: "upload" });
// });
// -- Swagger -- //
// server.get("/api-docs", (req, res, next) => {
// res.status(200).json({ data: {}, message: "swagger" });
// });
// -- Not Found MW -- //
server.use((req, res, next) => {
res.status(404).json({ error: { message: "Not Found _from app.js_" } });
});
// -- Error MW -- //
server.use((err, req, res, next) => {
console.log(err);
res.status(500).json({
message: "Something went wrong _from app.js_",
});
});