Created
July 27, 2015 16:20
-
-
Save jpoehls/a40db92ad2033ab7316f to your computer and use it in GitHub Desktop.
Proxy + Static File serving with caddy
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
# Caddyfile | |
localhost:2015 { | |
startup "go run ./server.go" & | |
root ./static_files | |
proxy / localhost:2016 | |
} | |
# FILE TREE | |
# | |
# │ Caddyfile | |
# │ server.go | |
# │ | |
# └───static_files | |
# styles.css |
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
// server.go | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", handler) | |
log.Fatalln(http.ListenAndServe(":2016", nil)) | |
} | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, ` | |
<html> | |
<head> | |
<link href="/styles.css" rel="stylesheet" /> | |
</head> | |
<body> | |
My background should be blue. | |
</body> | |
</html> | |
`) | |
} |
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
/* static_files/styles.css */ | |
body { | |
background-color: blue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment