-
Notifications
You must be signed in to change notification settings - Fork 15
/
app.js
54 lines (42 loc) · 1.38 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
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const mongoose = require("mongoose");
const errorHandler = require("./errorHandlers/errorHandler");
const indexRouter = require("./routes/index");
const userRouter = require("./routes/user");
const adminRoutes = require("./routes/adminRoutes");
const dashboardRoutes = require("./routes/dashboardRoutes");
const adminPanel = require("./routes/adminPanel");
// Skill ++ routes
const skillRoutes = require("./routes/skills/routes.js");
const app = express();
const connection = mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
})
.then(console.log(`MongoDB connected`))
.catch((err) => console.log(err));
app.set("view engine", "ejs");
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(
express.static(path.join(__dirname, "public"), { extensions: ["html"] })
);
app.use("/", indexRouter);
app.use("/", dashboardRoutes);
app.use("/api/user", userRouter);
app.use("/protected", adminRoutes);
// SKill ++
app.use("/skills", skillRoutes);
adminPanel(app, connection);
app.get("*", function (req, res) {
res.status(404).render("pages/404");
});
app.use(errorHandler);
module.exports = app;