all repos — vite @ 02c90b752aeecafd7c76262990e3a5e4b08bb446

a fast (this time, actually) and minimal static site generator

commands/serve.go (view raw)

 1package commands
 2
 3import (
 4	"fmt"
 5	"log"
 6	"net/http"
 7)
 8
 9func requestLog(h http.Handler) http.Handler {
10	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
11		h.ServeHTTP(w, r)
12		log.Printf("%s\t%s", r.Method, r.URL.Path)
13	})
14}
15
16func Serve(addr string) error {
17	fs := http.FileServer(http.Dir("./build"))
18	mux := http.NewServeMux()
19	mux.Handle("/", fs)
20	fmt.Printf("vite: serving on %s\n", addr)
21	if err := http.ListenAndServe(addr, requestLog(mux)); err != nil {
22		return err
23	}
24	return nil
25}