Created
June 3, 2019 14:23
-
-
Save sr229/2a0bb855e60aa32ec5dad82a09ea989e to your computer and use it in GitHub Desktop.
Skeleton implementation for Filo
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
/** | |
* Copyright 2019 (c) Kibo Hikari | |
* Licensed under MIT. | |
* | |
* Based on Google's Flywheel whitepaper | |
* If you want to read about it, see: https://ai.google/research/pubs/pub43447 | |
*/ | |
const http = require('http'); | |
const httpsProxy = require('http-proxy'); | |
const proxy = httpsProxy.createProxyServer({target: 'http://localhost:9001', ws: true}).listen(8090); | |
const server = http.createServer((req, res) => { | |
console.log(`Proxying ${req.url}`); | |
proxy.web(req, res, {target: req.url}); | |
proxy.on('error', e => { | |
console.error(`!-- Error: Failed to proxy ${req.url}\n\n Call stack \n\n ${e.stack}`); | |
}); | |
// support WSes | |
proxy.on('upgrade', (req, sock, head) => { | |
proxy.ws(req, sock, head, {target: req.url}) | |
}) | |
}); | |
console.log('Filo proxy running in Port 8000.\n If you are runnning this in Heroku, run it via port 80 and 443.') | |
server.listen(9001); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment