forked from madhanmaaz/white-spikes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
61 lines (49 loc) · 1.65 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
process.__dirname = __dirname
const { serverInit, getConfig, cout } = require("./utils/server-helpers")
const expressFileupload = require("express-fileupload")
const { startTunnel } = require("./utils/tunnel")
const expressDevice = require("express-device")
const cookieParser = require("cookie-parser")
const socketIo = require("socket.io")
const electron = require("electron")
const express = require("express")
const http = require("http")
const path = require("path")
const app = express()
const server = http.createServer(app)
const io = new socketIo.Server(server)
const PORT = process.env.PORT || getConfig('port')
serverInit()
app.use(express.static(path.join(__dirname, "public")))
app.use(express.urlencoded({ extended: false }))
app.set("views", path.join(__dirname, 'views'))
app.use(expressDevice.capture())
app.set("view engine", "ejs")
app.use(expressFileupload())
app.use(cookieParser())
app.use(express.json())
global.IO = io
// +======== cors config ==========+
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*")
res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
next()
})
// non admin check
app.use("/ws-app", require("./router/ws-app"))
// admin check
app.use("/", require("./router"))
app.use("/panel", require("./router/panel"))
server.listen(PORT, async () => {
await startTunnel()
cout.out(`LOCAL SERVER : http://localhost:${PORT}`)
cout.out(`TUNNEL SERVER : ${process.env.WSTUNNELURL}`)
})
electron.app.on("ready", () => {
cout.out("Electron browser ready.")
})
electron.app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit = false
}
})