-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
66 lines (54 loc) · 1.68 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
const express = require("express");
const path = require("path");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const io = require("./server").io;
const app = require("./server").app;
const cors = require("cors");
const ExpressError = require("./utils/ExpressError");
app.use("/images", express.static(path.join(__dirname, "images")));
app.use(express.static(path.join(__dirname, "/public")));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(cors());
const MONGO_URI = "mongodb://localhost/maleda";
mongoose
.connect(`${MONGO_URI}`, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log("Connected To Database Successfully");
})
.catch((e) => {
console.log("Error While Connecting to Database");
console.log(e);
});
app.get("/", (req, res) => {
res.json({
api: [
{
get: ["/products", "/producttype"],
post: ["/products", "/producttype", "/auth/login", "/auth/signup"],
put: ["/"],
},
],
});
});
const productRouter = require("./router/productRouter");
const authRouter = require("./router/authRouter");
const categoryRouter = require("./router/productTypeRouter");
// app.use("/", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.use("/products", productRouter);
app.use("/auth", authRouter);
app.use("/producttype", categoryRouter);
app.use("*", function (req, res, next) {
next(new ExpressError("Page Not Found", 404));
});
app.use(function (err, req, res, next) {
const { statusCode = 500 } = err;
if (!err.message) {
err.message = "Someting Went Wrong";
}
res.json({
msg: err,
status: statusCode,
});
});