all repos — vite @ bce0b549b8c10271ee7df30d6d7c78af2675cf6c

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}