-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (33 loc) · 1.07 KB
/
main.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
const express = require("express");
const app = express();
const mongoose = require("mongoose");
const fs = require("fs");
const config = JSON.parse(fs.readFileSync("./config.json").toString());
const PORT = config.Internal_Server_Port;
mongoose.set('strictQuery', true);
fs.readdirSync("./paths/activation").forEach(fileName => {
app.use(require(`./paths/activation/${fileName}`));
});
fs.readdirSync("./paths/account").forEach(fileName => {
app.use(require(`./paths/account/${fileName}`));
});
app.listen(PORT, () => {
console.log(`Server is running`);
}).on("error", async (err) => {
if (err.code == "EADDRINUSE") {
console.log("Port in use!");
process.exit(0);
} else throw err;
});
mongoose.connect(config.MongoDB_URI, () => {
console.log("App successfully connected to MongoDB!");
});
mongoose.connection.on("error", err => {
console.log("MongoDB failed to connect, please make sure you have MongoDB installed and running.");
throw err;
});
app.use((req, res, next) => {
res.json({
"Error": "Wrong Endpoint!"
});
});