MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Static

Method Static

pkg/web/web.go:350–360  ·  view source on GitHub ↗

Static adds the http.FileSystem under the defined prefix.

(prefix string, fs http.FileSystem)

Source from the content-addressed store, hash-verified

348
349// Static adds the http.FileSystem under the defined prefix.
350func (s *Server) Static(prefix string, fs http.FileSystem) {
351 prefix = "/" + strings.Trim(prefix, "/") + "/"
352 fileServer := http.StripPrefix(prefix, http.FileServer(fs))
353 s.router.PathPrefix(prefix).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
354 if hashRegex.MatchString(path.Base(r.URL.String())) {
355 w.Header().Set("Cache-Control", "public, max-age=604800, immutable")
356 w.Header().Del("Pragma")
357 }
358 fileServer.ServeHTTP(w, r)
359 })
360}
361
362// Prefix returns a route for the given path prefix.
363func (s *Server) Prefix(prefix string) *mux.Route {

Callers 2

NewFunction · 0.95
TestStaticFunction · 0.80

Calls 4

HeaderMethod · 0.80
StringMethod · 0.65
SetMethod · 0.65
ServeHTTPMethod · 0.45

Tested by 1

TestStaticFunction · 0.64