-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
76 lines (71 loc) · 2.67 KB
/
index.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
71
72
73
74
75
76
//
// Heliactyl 1.15, Codename Mannequin
//
// * Copyright SrydenCloud Limited
// * Please read the "License" file
//
const express = require('express')
const limit = require('express-limit').limit;
var session = require('express-session')
const chalk = require("chalk")
const db = require('./handler/DB')
const app = express()
var expressWs = require('express-ws')(app);
const prompt = require('prompt-sync')();
const fs = require("fs");
const wssettings = require("./webserver.json")
let port = JSON.parse(fs.readFileSync("./webserver.json")).port;
// Set Heliactyl release version
db.set("version","1.15.0-beta6")
app.set("view engine","ejs")
app.set("views","views/themes")
app.set('trust proxy', 1)
app.use(session({
secret: require('./handler/functions').randString(),
resave: false,
saveUninitialized: true,
cookie: { secure: true }
}))
app.use(limit({
max: 5,
period: 4 * 1000
}))
let settings = {
panel:{
url:(db.get("settings-panel") == undefined) ? "https://panel.example.com" : JSON.parse(db.get("settings-panel")).url,
key:(db.get("settings-panel") == undefined) ? "INVALID_KEY" : JSON.parse(db.get("settings-panel")).key
},
discord : {
id:(db.get("settings-discord") == undefined) ? "0" : JSON.parse(db.get("settings-discord")).clientid,
secret:(db.get("settings-discord") == undefined) ? "0" : JSON.parse(db.get("settings-discord")).secret,
callback:(db.get("settings-discord") == undefined) ? "0" : JSON.parse(db.get("settings-discord")).callback
}
}
if(!((db.get("settings-discord") == undefined) && (db.get("settings-panel") == undefined))) {
require('./handler/locations').getLocations()
require('./handler/eggs').getEggs()
}
let rf = require('fs').readdirSync("./routes")
for(let i = 0; i < rf.length; i++) {
let ab = require('./routes/'+rf[i])
if((db.get("settings-discord") == undefined) && (db.get("settings-panel") == undefined)) {
if((ab.path !== "/setup") && ab.path !== "/") {
console.log(chalk.yellowBright("API | Cannot load route '"+ab.path+"' as this instance is not setup!"))
}else{
app.use(ab.path,ab.router)
expressWs.applyTo(ab.router)
console.log(chalk.gray("API | Loaded route "+ab.path))
}
}else{
app.use(ab.path,ab.router)
console.log(chalk.gray("API | Loaded route "+ab.path))
expressWs.applyTo(ab.router)
}
}
app.get("*", async(req, res) => {
res.send("404")
})
console.log(chalk.blue("HELIACTYL | Instance successfully started!"))
console.log(chalk.blue("HELIACTYL | You are running version 1.15.0-beta6"))
console.log(chalk.green("WS | Heliactyl Webserver started!"))
app.listen(parseInt(port))