-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (45 loc) · 1.4 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
const express = require("express");
const mongoose = require("mongoose");
const morgan = require("morgan");
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const moment = require("moment");
const reload = require("reload");
const mainPages = require("./mainpages");
const muzRoutes = require("./routes/muzRoutes");
const ejs = require("ejs");
const http = require("http");
const app = express();
const server = http.createServer(app);
dotenv.config();
app.set("port", process.env.PORT || 5000);
app.locals.moment = moment;
app.locals.ejs = ejs;
const dbURI = process.env.MONGO_URI;
mongoose
.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then((result) => {
console.log("Connected to database");
app.listen(4000);
})
.catch((err) => console.log(err));
app.set("view engine", "ejs");
app.use(morgan("dev"));
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// load static files
app.use(express.static("public"));
app.get("/", (req, res) => {
res.render("index", { title: "Home", mainPages, req_url: req.url });
});
// load song routes
app.use("/muz-center", muzRoutes);
app.get("/muz", (req, res) => {
res.redirect("/muz-center");
});
reload(app);
// 404 page middleware
app.use((req, res) => {
res.status(404).render("404", { title: "404", mainPages, req_url: req.url });
});
server.listen(process.env.PORT || 5000);