-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
83 lines (65 loc) · 2.45 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
82
83
require('./polyfills');
require('dotenv').config({path:'./.env-sqwid-backend-testnet-dev'});
const constants = require('./constants');
const fs = require("fs");
if (!fs.existsSync(constants.TEMP_PATH)) {
fs.mkdirSync(constants.TEMP_PATH);
}
const express = require ('express');
const morgan = require ('morgan');
const helmet = require ('helmet');
const rateLimit = require ('express-rate-limit')
const app = express ();
const port = process.env.PORT || 80;
const initStatsWatch = require('./lib/initStatswatch');
const { initAutomod } = require('./lib/automod');
const firebase = require ('./lib/firebase');
// const redisClient = require ('./lib/redis');
const initAdminConfig = async () => {
try {
const configRef = firebase.collection('config');
const moderatorsDoc = configRef.doc('content_moderators');
const moderatorAddresses = process.env.MODERATORS?.split(',').map(addr => addr.trim()) || [];
await moderatorsDoc.set({
addresses: moderatorAddresses
}, { merge: true });
console.log('Content moderators configuration updated successfully');
} catch (error) {
console.error('Error updating content moderators:', error);
}
};
initStatsWatch();
initAutomod();
initAdminConfig();
/*const limiter = rateLimit ({
windowMs: 1 * 60 * 1000, // 1 minute
max: 60, // Limit each IP to 60 requests per `window`
standardHeaders: true,
legacyHeaders: false,
statusCode: 429
})*/
app.set ('trust proxy', 2);
app.use (morgan ('dev'));
app.use (helmet ());
if (process.env.ENABLE_CORS==='true') {
const cors = require ('cors');
app.use (cors ());
}
app.use (express.json ({ limit: "100mb" }));
app.use (express.urlencoded ({extended: true, limit: "100mb"}));
app.use (express.raw ({ type: "application/octet-stream", limit: "50mb" }));
// app.use (limiter);
const getRoutes = require ('./routes/index');
const {TEMP_PATH} = require("./constants");
app.use ('/', getRoutes());
app.use(function (err, req, res, next) {
console.log('app.use ERR=', err.stack);
res.status(500).send('Something broke!');
});
const server = app.listen (port, () => {
console.log (`Listening on port ${port}`);
});
// Ensure all inactive connections are terminated by the proxy, by setting this a few seconds higher than the proxy idle timeout
server.keepAliveTimeout = 77000;
// Ensure the headersTimeout is set higher than the keepAliveTimeout due to this nodejs regression bug: https://github.com/nodejs/node/issues/27363
server.headersTimeout = 78000;