-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpconfig.ts
More file actions
88 lines (76 loc) · 1.93 KB
/
httpconfig.ts
File metadata and controls
88 lines (76 loc) · 1.93 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
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
84
85
86
87
88
import compression from 'compression';
import dns from 'dns';
import express, { Request, Response } from 'express';
import path from 'path';
interface RequestField {
displayName: string;
value: string | string[] | undefined;
}
interface RemoteRequest {
ip: RequestField;
hostname: RequestField;
ua: RequestField;
language: RequestField;
connection: RequestField;
encoding: RequestField;
mimeType: RequestField;
charset: RequestField;
}
const app = express();
const port = parseInt(process.env.PORT ?? '9000', 10);
app.set('trust proxy', true);
app.use(compression());
app.use('/static', express.static(path.join(__dirname, 'static')));
app.get('/', (req: Request, res: Response) => {
res.sendFile(path.join(__dirname, 'static/html/httpconfig.html'));
});
app.get('/api/httpconfig', (req: Request, res: Response) => {
const remoteReq: RemoteRequest = {
ip: {
displayName: 'IP Address',
value: req.ip,
},
hostname: {
displayName: 'Remote Host',
value: '',
},
ua: {
displayName: 'User Agent',
value: req.headers['user-agent'],
},
language: {
displayName: 'Language',
value: req.headers['accept-language'],
},
connection: {
displayName: 'Connection',
value: req.headers.connection,
},
encoding: {
displayName: 'Encoding',
value: req.headers['accept-encoding'],
},
mimeType: {
displayName: 'MIME Type',
value: req.headers.accept,
},
charset: {
displayName: 'Charset',
value: req.headers['accept-charset'],
},
};
dns.reverse(req.ip ?? '', (err, domains) => {
if (domains) {
remoteReq.hostname.value = domains[0];
}
res.json(remoteReq);
});
});
app.use((req: Request, res: Response) => {
res.status(404).send("404: Sorry, we've had an error.");
});
if (require.main === module) {
app.listen(port);
console.log('Listening on port ' + port);
}
export default app;