🏗️ Use static module for serving static files

This commit is contained in:
Maxim Lebedev 2023-11-19 13:52:42 +06:00
parent 62bc90fd3e
commit 867782367e
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
1 changed files with 1 additions and 2 deletions

View File

@ -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
}