Static adds the http.FileSystem under the defined prefix.
(prefix string, fs http.FileSystem)
| 348 | |
| 349 | // Static adds the http.FileSystem under the defined prefix. |
| 350 | func (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. |
| 363 | func (s *Server) Prefix(prefix string) *mux.Route { |