-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (47 loc) · 1.28 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
require('dotenv').config();
const express = require('express');
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/other/errors.js');
const { version, description } = require('./package.json');
// Run express instance
const app = express();
// Set
app.set('trust proxy', 1);
// Use
app.use(helmet({ crossOriginEmbedderPolicy: false, crossOriginResourcePolicy: false }));
app.use(logger);
app.use(limiter);
app.use(timeout());
app.use(express.static('public'));
// Endpoints
app.get('/', (req, res) =>
res.type('json').send(JSON.stringify({
success: true,
status: 200,
message: description,
version,
worker: process.pid,
domains: {
main: 'https://sefinek.net',
api: 'https://api.sefinek.net',
cdn: 'https://cdn.sefinek.net',
},
}, null, 4)),
);
// Errors
app.use(notFound);
app.use(internalError);
// Run server
app.listen(process.env.PORT, () => {
if (process.env.NODE_ENV === 'production') {
try {
process.send('ready');
} catch (err) {
// . . .
}
}
console.log(`Website https://screenshots.sefinek.net is running on http://127.0.0.1:${process.env.PORT}`);
});