add go program to serve localhost with proper CORS and range support

This commit is contained in:
Brandon Liu
2021-02-17 15:51:30 +08:00
parent 530c10444d
commit 508186c4db

View File

@@ -0,0 +1,22 @@
package main
import (
"flag"
"log"
"net/http"
)
func main() {
port := flag.String("p", "7000", "port to serve on")
directory := flag.String("d", ".", "the directory containing PMTiles archives")
flag.Parse()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "Range")
http.ServeFile(w, r, r.URL.Path[1:])
})
log.Printf("Serving %s on HTTP port: %s\n", *directory, *port)
log.Fatal(http.ListenAndServe(":"+*port, nil))
}