Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created July 10, 2020 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhoff/a85f4edbbc10d71b389f21a80c9b8bde to your computer and use it in GitHub Desktop.
Save alanhoff/a85f4edbbc10d71b389f21a80c9b8bde to your computer and use it in GitHub Desktop.
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