Browse Source

simplify static file handler

static
Jeffrey Paul 6 months ago
parent
commit
52ce35e8c3
2 changed files with 1 additions and 15 deletions
  1. +0
    -14
      httpserver/handlestatic.go
  2. +1
    -1
      httpserver/routes.go

+ 0
- 14
httpserver/handlestatic.go View File

@@ -1,14 +0,0 @@
package httpserver

import (
"net/http"
)

func (s *server) staticHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// sadly, the route prefix needs to be reproduced here, so it knows
// how to convert the incoming request path to the appropriate
// embedded file path
http.StripPrefix("/s", http.FileServer(s.staticFiles.HTTPBox())).ServeHTTP(w, r)
}
}

+ 1
- 1
httpserver/routes.go View File

@@ -58,7 +58,7 @@ func (s *server) routes() {

s.router.Get("/", s.handleIndex())

s.router.Mount("/s", s.staticHandler())
s.router.Mount("/s", http.StripPrefix("/s", http.FileServer(s.staticFiles.HTTPBox())))

s.router.Route("/api/v1", func(r chi.Router) {
r.Get("/now", s.handleNow())

Loading…
Cancel
Save