🏗️ Use static module for serving static files
This commit is contained in:
parent
62bc90fd3e
commit
867782367e
3
main.go
3
main.go
|
@ -83,13 +83,12 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
|||
pages := pagefsrepo.NewFileSystemPageRepository(contentDir)
|
||||
pager := pageucase.NewPageUseCase(pages, resources)
|
||||
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// TODO(toby3d): use exists static use case or split that on static and resource modules?
|
||||
// INFO(toby3d): any static file is public and unprotected by design, so it's safe to search it
|
||||
// first before deep down to any page or it's resource which might be secured by middleware or
|
||||
// something else.
|
||||
static, err := staticer.Do(r.Context(), strings.TrimPrefix(r.URL.Path, "/"))
|
||||
if err == nil {
|
||||
http.ServeContent(w, r, static.Name(), domain.ResourceModTime(static), static)
|
||||
http.ServeContent(w, r, static.Name(), static.ModTime(), static)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue