forked from XpI0It/3xploit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (60 loc) · 1.71 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
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require("express");
const exphbs = require("express-handlebars");
const app = express();
const mongoose = require("mongoose");
// database
const database = (module.exports = () => {
const connectionParameters = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
try {
mongoose.connect(
"mongodb+srv://PRJ:PRJ666@cluster0.gqgjk6y.mongodb.net/?retryWrites=true&w=majority"
),
connectionParameters;
console.log("Database connection successful");
} catch (error) {
console.log(error);
}
});
database();
//Static Files (CSS, Images)
app.use("/static", express.static(`${__dirname}/static`));
// scripts (JS)
app.use("/scripts", express.static(`${__dirname}/scripts`));
// resource files (JSON)
app.use("/res", express.static(`${__dirname}/res`));
// data parsing middleware
// Parse application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
var Handlebars = require("handlebars");
Handlebars.registerHelper("inc", function (value, options) {
return parseInt(value) + 1;
});
// Handlebars middleware
app.set("view engine", ".hbs");
app.engine(
".hbs",
exphbs({
extname: ".hbs",
defaultLayout: "main",
})
);
// main routes
app.use("/", require("./routes/main"));
// Login/Register form routes
app.use("/users", require("./routes/users"));
app.use("/game", require("./routes/game"));
app.use("/scores", require("./routes/leaderboard"));
//err handling
app.use((req, res) => {
res.status(404).send("<i>something broke :/</i>");
});
//port
const HTTP_PORT = process.env.PORT || 8080;
app.listen(HTTP_PORT, (err) => {
if (err) console.log(err);
else console.log(`=> Started at http://localhost:${HTTP_PORT}`);
});