-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (53 loc) · 1.68 KB
/
server.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
if (process.env.NODE_ENV != "production") {
//dotenv is used to store environment variables in a .env file which is secure
require("dotenv").config();
}
const express = require("express");
const app = express();
const server = require("http").createServer(app);
const port = process.env.PORT || 3000;
const { instrument } = require("@socket.io/admin-ui");
global.io = require("socket.io")(server, {
cors: {
origin: ["https://admin.socket.io"],
credentials: true
}
});
instrument(io, {
auth: false
});
const path = require("path");
//Load the Controller files
const indexRouter = require("./routes/index");
const userRouter = require("./routes/user");
const projectRouter = require("./routes/project");
const mongooose = require("mongoose");
//connect to mongo db
mongooose.connect(process.env.DB_URL, { useNewUrlParser: true });
const db = mongooose.connection;
db.on("error", err => {
console.log(err);
});
db.once("open", () => {
console.log("connected to database");
});
//set up the view engine to ejs for loading variables in the views
app.set("view engine", "ejs");
app.set("views", __dirname + "/views");
//Full public access to the public folder
app.use(express.static(path.join("public")));
//set the controller routes
//root url forward to index.js
app.use("/", indexRouter);
//user url forward to user.js
app.use("/user", userRouter);
//project url forward to project.js
app.use("/user/project", projectRouter);
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
server.listen(port, () => {
console.log(`application is running at: http://localhost:${port}`);
});
app.get("/admin", (req, res) => {
res.render("admin/admin")
})