-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
60 lines (52 loc) · 1.72 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
const http = require("http");
const express = require("express");
const app = express();
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server, {
cors: {
origin: "*",
},
});
const fs = require("fs");
const path = require("path");
async function Init() {
const configFileExists = fs.existsSync(path.join(process.cwd(), "config.js"));
const streamConfigFileExists = fs.existsSync(path.join(process.cwd(), "streamConfig.js"));
const firstRun = !(configFileExists && streamConfigFileExists);
if (firstRun) {
if (!configFileExists) {
await fs.copyFileSync(
path.join(__dirname, "templates/config.default.js"),
path.join(process.cwd(), "config.js")
);
console.log("Default config file created! Please re-run the program after you complete!");
}
if (!streamConfigFileExists) {
await fs.copyFileSync(
path.join(__dirname, "templates/streamConfig.default.js"),
path.join(process.cwd(), "streamConfig.js")
);
console.log(
"Default streamConfig file created! Please re-run the program after you complete!"
);
}
process.exit();
} else {
const config = require(path.join(process.cwd(), "config.js"));
// osu!api (v2) init
require("./osuApi")(config);
// Static Folder
app.use("/", express.static(path.join(__dirname, "public")));
// API
const api = require("./api")(config);
app.use("/api", api);
// Info fetching and sending to browser
require("./update")(config, io.of("/update"));
// Run Server
server.listen(config.port, () => {
console.log(`KDC overlay backend server running at http://localhost:${config.port}/`);
});
}
}
Init();