forked from uNetworking/uWebSockets.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyProtocol.js
More file actions
25 lines (23 loc) · 805 Bytes
/
ProxyProtocol.js
File metadata and controls
25 lines (23 loc) · 805 Bytes
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
/* Minimal SSL/non-SSL example using PROXY Protocol v2 */
const uWS = require('../dist/uws.js');
const port = 3000;
const app = uWS./*SSL*/App({
key_file_name: 'misc/key.pem',
cert_file_name: 'misc/cert.pem',
passphrase: '1234'
}).get('/*', (res, req) => {
/* Respond with their addresses */
res.cork(() => {
res.write('<html><h1>');
res.write('Your proxied IP is: ' + Buffer.from(res.getProxiedRemoteAddressAsText()).toString());
res.write('</h1><h1>');
res.write('Your IP as seen by the origin server is: ' + Buffer.from(res.getRemoteAddressAsText()).toString());
res.end('</h1></html>');
});
}).listen(port, (listenSocket) => {
if (listenSocket) {
console.log('Listening to port ' + port);
} else {
console.log('Failed to listen to port ' + port);
}
});