Last active
August 29, 2015 14:04
-
-
Save danshearmur/508cea11f9a0211619a6 to your computer and use it in GitHub Desktop.
Revisions
-
danshearmur revised this gist
Jul 25, 2014 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,13 +39,14 @@ func serv(proxy string, port string) { http.HandleFunc("/css/", func(res http.ResponseWriter, req *http.Request) { path := req.URL.Path[1:] get, err := http.Get(proxy + strings.Replace(path, "css", "", 1)) if err != nil { http.NotFound(res, req) return } defer get.Body.Close() content, _ := ioutil.ReadAll(get.Body) res.Header().Set("Content-Type", "text/css") io.WriteString(res, string(content)) }) -
Daniel Shearmur revised this gist
Jul 25, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ * Serve the current directory * Map some extra paths to `/index.html` * Also proxy `/css/*` to a seperate webservice Usage: -
Daniel Shearmur revised this gist
Jul 25, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,6 @@ Also proxy "/css/*" to a seperate webservice Usage: ``` PORT=8080 PROXY_URL="http://localhost:5455/27850" go run main.go ``` -
Daniel Shearmur revised this gist
Jul 25, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,5 @@ Serve the current directory and map some extra paths to "/index.html" Also proxy "/css/*" to a seperate webservice Usage: PORT=8080 PROXY_URL="http://localhost:5455/27850" go run main.go -
Daniel Shearmur revised this gist
Jul 25, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,4 @@ Serve the current directory and map some extra paths to "/index.html" Also proxy "/css/*" to a seperate webservice Usage: ```PORT=8080 PROXY_URL="http://localhost:5455/27850" go run main.go``` -
Daniel Shearmur revised this gist
Jul 25, 2014 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ Serve the current directory and map some extra paths to "/index.html" Also proxy "/css/*" to a seperate webservice Usage: PORT=8080 PROXY_URL="http://localhost:5455/27850" go run main.go -
Daniel Shearmur created this gist
Jul 25, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ package main import ( "io" "io/ioutil" "net/http" "os" "strings" ) var allowedPaths = []string{ "photo", "characteristics", "interests", "personality", "introduction", "verification", } func contains(needle string, haystack []string) bool { for i := 0; i < len(haystack); i++ { if haystack[i] == needle { return true } } return false } func serv(proxy string, port string) { http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) { path := req.URL.Path[1:] if contains(path, allowedPaths) { http.ServeFile(res, req, "index.html") } else { http.StripPrefix("/", http.FileServer(http.Dir(""))).ServeHTTP(res, req) } }) http.HandleFunc("/css/", func(res http.ResponseWriter, req *http.Request) { path := req.URL.Path[1:] get, _ := http.Get(proxy + strings.Replace(path, "css", "", 1)) defer get.Body.Close() content, _ := ioutil.ReadAll(get.Body) res.Header().Set( "Content-Type", "text/css", ) io.WriteString(res, string(content)) }) http.ListenAndServe(":"+port, nil) } func main() { proxy := os.Getenv("PROXY_URL") if proxy == "" { panic("please specify PROXY_URL environment variable") } port := os.Getenv("PORT") if port == "" { port = "9000" } serv(proxy, port) }