-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
server.js
51 lines (39 loc) · 1.29 KB
/
server.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
const express = require('express')
const { rateLimit } = require('express-rate-limit')
const { createRequestHandler } = require('@remix-run/express')
const serverBuild = require('./build/index')
const app = express()
app.set('trust proxy', true);
// Fly.io proxy is compressing so we don't need here at the app level:
// app.use(compression());
// limit the bots that are hitting this at a fast rate
const limiter = rateLimit({
windowMs: 8 * 1000,
limit: 5,
standardHeaders: 'draft-7',
legacyHeaders: false,
})
app.use('/account/*', limiter);
app.use((req, res, next) => {
res.on('finish', () => {
const ip = req.headers['x-forwarded-for'] || req.socket.remoteAddress;
const path = req.originalUrl || req.url;
const log = `${ip} - - [${new Date().toISOString()}] "${req.method} ${path} HTTP/${req.httpVersion}" ${res.statusCode} ${res.get('Content-Length') || 0} "-" "${req.headers['user-agent']}"`;
console.log(log);
});
next();
});
app.use(express.static("public"));
app.all(
'*',
createRequestHandler({
build: serverBuild,
getLoadContext() {
},
})
)
const port = process.env.PORT ?? 3000
const host = '0.0.0.0'
app.listen(port, host, () => {
console.log(`Express server listening on port ${port}`)
})