Fix SSE architecture for reliable connections (#13)
This commit was merged in pull request #13.
This commit is contained in:
5
assets/assets.go
Normal file
5
assets/assets.go
Normal file
@@ -0,0 +1,5 @@
|
||||
// Package assets provides static file serving with build-tag switching
|
||||
// between live filesystem (dev) and embedded hashfs (prod).
|
||||
package assets
|
||||
|
||||
const DirectoryPath = "assets"
|
||||
File diff suppressed because one or more lines are too long
22
assets/static_dev.go
Normal file
22
assets/static_dev.go
Normal file
@@ -0,0 +1,22 @@
|
||||
//go:build dev
|
||||
|
||||
package assets
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func Handler() http.Handler {
|
||||
log.Debug().Str("path", DirectoryPath).Msg("static assets served from filesystem")
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
http.StripPrefix("/assets/", http.FileServerFS(os.DirFS(DirectoryPath))).ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func StaticPath(path string) string {
|
||||
return "/assets/" + path
|
||||
}
|
||||
26
assets/static_prod.go
Normal file
26
assets/static_prod.go
Normal file
@@ -0,0 +1,26 @@
|
||||
//go:build !dev
|
||||
|
||||
package assets
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"net/http"
|
||||
|
||||
"github.com/benbjohnson/hashfs"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed css js
|
||||
staticFiles embed.FS
|
||||
staticSys = hashfs.NewFS(staticFiles)
|
||||
)
|
||||
|
||||
func Handler() http.Handler {
|
||||
log.Debug().Msg("static assets are embedded with hashfs")
|
||||
return hashfs.FileServer(staticSys)
|
||||
}
|
||||
|
||||
func StaticPath(path string) string {
|
||||
return "/" + staticSys.HashName(path)
|
||||
}
|
||||
Reference in New Issue
Block a user