static_javascript.go 803 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "time"
  8. "miniflux.app/http/request"
  9. "miniflux.app/http/response"
  10. "miniflux.app/http/response/html"
  11. "miniflux.app/ui/static"
  12. )
  13. func (h *handler) showJavascript(w http.ResponseWriter, r *http.Request) {
  14. filename := request.RouteStringParam(r, "name")
  15. etag, found := static.JavascriptBundleChecksums[filename]
  16. if !found {
  17. html.NotFound(w, r)
  18. return
  19. }
  20. response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
  21. b.WithHeader("Content-Type", "text/javascript; charset=utf-8")
  22. b.WithBody(static.JavascriptBundles[filename])
  23. b.Write()
  24. })
  25. }