Skip to content

Commit 1b6c029

Browse files
committed
Add ProxyProtocol.js example
1 parent cc4a910 commit 1b6c029

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎examples/ProxyProtocol.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Minimal SSL/non-SSL example using PROXY Protocol v2 */
2+
3+
const uWS = require('../dist/uws.js');
4+
const port = 3000;
5+
6+
const app = uWS./*SSL*/App({
7+
key_file_name: 'misc/key.pem',
8+
cert_file_name: 'misc/cert.pem',
9+
passphrase: '1234'
10+
}).get('/*', (res, req) => {
11+
/* Respond with their addresses */
12+
res.cork(() => {
13+
res.write('<html><h1>');
14+
res.write('Your proxied IP is: ' + Buffer.from(res.getProxiedRemoteAddressAsText()).toString());
15+
res.write('</h1><h1>');
16+
res.write('Your IP as seen by the origin server is: ' + Buffer.from(res.getRemoteAddressAsText()).toString());
17+
res.end('</h1></html>');
18+
});
19+
}).listen(port, (listenSocket) => {
20+
if (listenSocket) {
21+
console.log('Listening to port ' + port);
22+
} else {
23+
console.log('Failed to listen to port ' + port);
24+
}
25+
});

0 commit comments

Comments
 (0)