Very very simple static HTML server to use for local projects
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

is this really all it takes?

graphiteisaac e5fe21c0

+53
+1
.gitignore
··· 1 + bin/
+50
cmd/goserve/goserve.go
··· 1 + package main 2 + 3 + import ( 4 + "log" 5 + "net/http" 6 + "os" 7 + ) 8 + 9 + func main() { 10 + if len(os.Args) < 2 { 11 + log.Fatalf("Failed to start: serve dir not provided") 12 + } 13 + 14 + // Define the directory where your static HTML files are located 15 + staticDir := os.Args[1] 16 + 17 + // Create a FileServer to serve files from the static directory 18 + fs := http.FileServer(http.Dir(staticDir)) 19 + 20 + // Create a custom handler function 21 + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 22 + // Log the request 23 + log.Printf("%s %s %s", 24 + r.Method, 25 + r.URL.Path, 26 + r.RemoteAddr, 27 + ) 28 + 29 + // Check if the request path points to a file that exists 30 + // without the .html extension, and if so, append it internally. 31 + // This allows requests like "/about" to serve "about.html". 32 + filePath := r.URL.Path 33 + if _, err := http.Dir(staticDir).Open(filePath); err != nil { 34 + // If the file without .html doesn't exist, try with .html 35 + filePathWithExt := filePath + ".html" 36 + if _, err := http.Dir(staticDir).Open(filePathWithExt); err == nil { 37 + r.URL.Path += ".html" 38 + } 39 + } 40 + 41 + // Serve the modified request using the FileServer 42 + fs.ServeHTTP(w, r) 43 + }) 44 + 45 + log.Println("Serving on :8080") 46 + err := http.ListenAndServe(":8080", nil) 47 + if err != nil { 48 + log.Fatal(err) 49 + } 50 + }
+1
test/article.html
··· 1 + <h1>Article</h1>
+1
test/index.html
··· 1 + <h1>Index</h1>