Skip to content

Instantly share code, notes, and snippets.

@jpoehls
Created July 27, 2015 16:20
Show Gist options
  • Save jpoehls/a40db92ad2033ab7316f to your computer and use it in GitHub Desktop.
Save jpoehls/a40db92ad2033ab7316f to your computer and use it in GitHub Desktop.
Proxy + Static File serving with caddy
# Caddyfile
localhost:2015 {
startup "go run ./server.go" &
root ./static_files
proxy / localhost:2016
}
# FILE TREE
#
# │ Caddyfile
# │ server.go
# │
# └───static_files
# styles.css
// 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>
`)
}
/* 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