From 1b6c029cc1f5000e7bc6467af255935e7386d30c Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 8 Jun 2020 14:17:36 +0200 Subject: [PATCH] Add ProxyProtocol.js example --- examples/ProxyProtocol.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/ProxyProtocol.js diff --git a/examples/ProxyProtocol.js b/examples/ProxyProtocol.js new file mode 100644 index 0000000..c0d4165 --- /dev/null +++ b/examples/ProxyProtocol.js @@ -0,0 +1,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('

'); + res.write('Your proxied IP is: ' + Buffer.from(res.getProxiedRemoteAddressAsText()).toString()); + res.write('

'); + res.write('Your IP as seen by the origin server is: ' + Buffer.from(res.getRemoteAddressAsText()).toString()); + res.end('

'); + }); +}).listen(port, (listenSocket) => { + if (listenSocket) { + console.log('Listening to port ' + port); + } else { + console.log('Failed to listen to port ' + port); + } +});