Created
May 23, 2020 20:35
-
-
Save scorredoira/62c10abae0e8c44cfda3bbc2241adca6 to your computer and use it in GitHub Desktop.
TLS Reverse proxy
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
import "stdlib/native" | |
export function main() { | |
let url = http.parseURL("https://example.com/") | |
let proxy = httputil.newSingleHostReverseProxy(url) | |
let server = http.newServer() | |
server.addressTLS = ":9999" | |
let c = tls.generateCert() | |
let tlsConf = tls.newConfig(true) | |
tlsConf.loadCertificateData(c.cert, c.key) | |
server.tlsConfig = tlsConf | |
server.handler = (w, r) => { | |
r.url.host = url.host | |
r.url.scheme = url.scheme | |
r.host = url.host | |
proxy.serveHTTP(w, r) | |
} | |
server.start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment