summaryrefslogtreecommitdiff
path: root/web/web.go
diff options
context:
space:
mode:
authora73x <[email protected]>2024-12-22 12:12:50 +0000
committera73x <[email protected]>2024-12-22 12:12:50 +0000
commitf1cc5903f84fe41c1e9566768d53d95f6be20236 (patch)
treee642dd7dd19df924aa0345fffc2b89f28d6186a0 /web/web.go
parent6beea1d4127d2d51bfdc75162423407c198d19da (diff)
hack in some hotreloading
Diffstat (limited to 'web/web.go')
-rw-r--r--web/web.go46
1 files changed, 0 insertions, 46 deletions
diff --git a/web/web.go b/web/web.go
deleted file mode 100644
index 96f85d2..0000000
--- a/web/web.go
+++ /dev/null
@@ -1,46 +0,0 @@
-package web
-
-import (
- "net/http"
- "time"
-
- "git.sr.ht/~a73x/home/pages"
- "go.uber.org/zap"
-)
-
-func New(logger *zap.Logger) (*http.Server, error) {
- loggingMiddleware := func(next http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- start := time.Now()
- next.ServeHTTP(w, r)
- logger.Info("request received",
- zap.String("url", r.URL.Path),
- zap.String("method", r.Method),
- zap.Duration("duration", time.Since(start)),
- zap.String("user-agent", r.UserAgent()),
- )
- })
- }
-
- mux := http.NewServeMux()
- pages, err := pages.Collect("./content")
- if err != nil {
- return nil, err
- }
-
- staticFs := http.FileServer(http.Dir("./public/static"))
-
- mux.Handle("GET /static/", http.StripPrefix("/static/", staticFs))
- for _, page := range pages {
- mux.HandleFunc("GET "+page.Path, func(w http.ResponseWriter, r *http.Request) {
- w.Write([]byte(page.Content))
- })
- }
-
- server := http.Server{
- Addr: ":8080",
- Handler: loggingMiddleware(mux),
- }
-
- return &server, nil
-}