-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (40 loc) · 1.36 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
//imports
const express = require("express");
const cors = require("cors");
const morgan = require("morgan");
const dotenv = require("dotenv");
const connectDB = require("./src/models");
const userRouter = require("./src/api/User/user.routes");
const passport = require("passport");
const { localStrategy, jwtStrategy } = require("./src/middleware/passport");
const errorHandler = require("./src/middleware/errorHandler");
const notFoundHandler = require("./src/middleware/notFoundHandler");
const categoryRouter = require("./src/api/Category/category.routes");
const resturantRouter = require("./src/api/Resturant/resturant.routes");
const itemRouter = require("./src/api/Item/item.routes");
const path = require("path");
//inits
dotenv.config();
const app = express();
app.use(cors());
app.use(morgan("dev"));
const PORT = process.env.PORT || 5000;
//middlewares
app.use(express.json());
app.use(passport.initialize());
passport.use("local", localStrategy);
passport.use("jwt", jwtStrategy);
//routes
app.use("/api/auth", userRouter);
app.use("/api/category", categoryRouter);
app.use("/api/resturant", resturantRouter);
app.use("/api/item", itemRouter);
//middlewares
app.use('/media', express.static(path.join(__dirname, "media")));
app.use(errorHandler);
app.use(notFoundHandler);
//server
connectDB();
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});