-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
49 lines (39 loc) · 1.38 KB
/
app.js
File metadata and controls
49 lines (39 loc) · 1.38 KB
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
/* eslint-disable no-unused-vars */
import config from './config/config.json';
import mysql from 'mysql2/promise';
import express from 'express';
import rateLimit from 'express-rate-limit';
import morgan from 'morgan';
import { stream } from './src/winston.js'
import * as gdstatus from './src/gdstatus/gdstatus.js'
import * as ownAPI from './src/api/api.js'
//Mysql
const connection = mysql.createPool({
host: config.mysql_host,
user: config.mysql_user,
password: config.mysql_password,
port: config.mysql_port,
database: config.mysql_database,
multipleStatements: true
});
const limiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100 // limit each IP to 100 requests per windowMs
});
const app = express();
morgan.token('ip-addr', function (req, res) { return req.headers['x-forwarded-for'] });
app.use(morgan('[:date[clf]] :ip-addr - :remote-user ":method :url HTTP/:http-version" :status ":user-agent" - :response-time ms', {stream}));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(limiter);
gdstatus.setConnection(connection);
app.use('/gdstatus', gdstatus.router);
ownAPI.setConnection(connection);
app.use('/api', ownAPI.router);
app.use(function(req, res, next) {
res.status(404);
res.send("Not Found");
});
app.listen(config.web_port, () => {
console.log(`running in ${config.web_port} port!`);
});