-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (64 loc) · 2.17 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
77
78
79
80
81
var express = require('express')
var app = express()
var hpp = require('hpp')
var slowDown = require('express-slow-down')
var helmet = require('helmet')
let fs = require('fs')
const sql = require("./nodejs/sql.js")
sql.init()
const CLEANUP_INTERVAL = 60; //in minutes
const cleanup = require("./nodejs/cleanup.js")
var cleanuphandler = setInterval(cleanup, CLEANUP_INTERVAL * 60 * 1000)
process()
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
//set localhost as trusted proxy
app.set('trust proxy', 'loopback') // specify a single subnet
//prevent http parameter pollution
app.use(hpp())
//slow down requests
var speedLimiter = slowDown({
windowMs: 1000 * 60 * 2, //2 minutes
delayAfter: 1024,
delayMs: 100 //add 100ms per request
})
app.use(speedLimiter)
//add helmet for additional security
app.use(helmet())
// to import another router
// app.use(require("./nodejs/test.js"))
app.use(require("./nodejs/api/createUser.js"))
app.use(require("./nodejs/api/doesUserTokenExist.js"))
app.use(require("./nodejs/api/createLobby.js"))
app.use(require("./nodejs/api/changeName.js"))
app.use(require("./nodejs/api/getUser.js"))
app.use(require("./nodejs/api/getLobby.js"))
app.use(require("./nodejs/api/getLobbies.js"))
app.use(require("./nodejs/api/leaveLobby.js"))
app.use(require("./nodejs/api/joinLobby.js"))
app.use(require("./nodejs/api/play.js"))
app.use(require("./nodejs/api/spectate.js"))
app.use(require("./nodejs/api/rematch.js"))
app.use(require("./nodejs/api/doesUserNameExist.js"))
app.use(require("./nodejs/api/quickgame.js"))
app.use(require("./nodejs/api/requestai.js"))
const DIR = "./docs/"
app.get('/index.html', function (req, res) {
res.redirect('/')
})
app.get('/manifest.json', function (req, res) {
let options = { root: DIR }
res.sendFile("manifest2.json", options)
})
app.use(express.static(DIR))
app.get('/', function (req, res) {
res.render(DIR + 'index.html')
})
app.listen(5500, '0.0.0.0')
async function process() {
//console.log( await sql.getUserByToken("abc"))
//console.log( await sql.getLobbies());
//console.log(await sql.getUsers())
// console.log(await sql.getLobbies())
}