Skip to content

Instantly share code, notes, and snippets.

@scorredoira
Created May 23, 2020 20:35
Show Gist options
  • Save scorredoira/62c10abae0e8c44cfda3bbc2241adca6 to your computer and use it in GitHub Desktop.
Save scorredoira/62c10abae0e8c44cfda3bbc2241adca6 to your computer and use it in GitHub Desktop.
TLS Reverse proxy
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