Created
July 10, 2020 11:08
-
-
Save alanhoff/a85f4edbbc10d71b389f21a80c9b8bde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const httpProxy = require('http-proxy'); | |
const proxy = httpProxy.createProxyServer({ | |
target: { | |
host: 'pulsar-host', | |
port: 8080 | |
} | |
}); | |
const server = http.createServer((req, res) => { | |
res.writeHead(404); // We only accept ws requests | |
res.end(); | |
}); | |
server.on('upgrade', (req, socket, head) => { | |
// Authenticate your client here | |
// if authentication is successfull then: | |
proxy.ws(req, socket, head); | |
// if authentication fails then: | |
socket.destroy(); | |
}); | |
server.listen(8080); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment