Skip to content

Instantly share code, notes, and snippets.

@brejoc
Forked from jpoehls/Caddyfile
Created February 15, 2017 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brejoc/ddcd77a5fc4ea3b904bbef761a9676ff to your computer and use it in GitHub Desktop.
Save brejoc/ddcd77a5fc4ea3b904bbef761a9676ff 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