-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (39 loc) · 1.36 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
require('dotenv').config();
const express = require('express');
const { networkInterfaces } = require('node:os');
const { version } = require('./package.json');
// Middleware imports
const helmet = require('helmet');
const timeout = require('./middlewares/timeout.js');
const logger = require('./middlewares/morgan.js');
const limiter = require('./middlewares/ratelimit.js');
const { notFound, internalError } = require('./middlewares/errors.js');
// Network interfaces
const port = process.env.PORT;
const getLocalNetworkLinks = () => {
return Object.values(networkInterfaces())
.flat()
.filter(net => net.family === 'IPv4' && !net.internal)
.map(net => `http://${net.address}:${port}`);
};
// Create an Express app
const app = express();
// Middlewares
app.use(helmet());
app.use(express.json({ limit: '6kb' }));
app.use(logger);
app.use(limiter);
app.use(timeout());
const MainRouter = require('./routes/Index.js');
app.use(MainRouter);
// Errors
app.use(notFound);
app.use(internalError);
// Listen
app.listen(port, () => {
const localLinks = getLocalNetworkLinks();
console.log(`[${process.env.NODE_ENV.toUpperCase()}] Waiting for events - v${version}`);
console.log(`- Local: http://127.0.0.1:${port}/discord/webhook`);
localLinks.forEach(link => console.log(`- Network: ${link}/discord/webhook`));
if (process.env.NODE_ENV === 'production') process.send('ready');
});