Created
December 11, 2019 09:19
-
-
Save podhmo/24e0cdb4d3a1288f59ba826f6925a09b 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
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"os" | |
) | |
func main() { | |
// port, backendServerURL, staticDir | |
port := os.Args[1] | |
backendServerURL := os.Args[2] | |
staticDir := os.Args[3] | |
rpURL, err := url.Parse(backendServerURL) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Fprintf(os.Stderr, "start: port=%q, staticDir=%q\n", port, staticDir) | |
mux := http.DefaultServeMux | |
mux.Handle("/", httputil.NewSingleHostReverseProxy(rpURL)) | |
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))) | |
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), mux); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment