Skip to content

Commit

Permalink
Fix createDirFile
Browse files Browse the repository at this point in the history
  • Loading branch information
snmed committed Feb 24, 2019
1 parent 867ab93 commit 2b907c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
1 change: 1 addition & 0 deletions example/webapp-backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func main() {
http.HandleFunc("/api/time", timeHandler)

http.Handle("/files/", http.StripPrefix("/files/", http.FileServer(loader)))
http.Handle("/files2/", http.StripPrefix("/files2/", http.FileServer(http.Dir("../webapp-frontend/build"))))

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fp := r.URL.Path
Expand Down
43 changes: 12 additions & 31 deletions example/webapp-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions templ.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,22 @@ func (l loader) Open(name string) (http.File, error) {
if !strings.HasPrefix(name, "/") {
name = "/" + name
}
name = strings.TrimRight(name, "/")
if len(name) > 1 && name[len(name)-1] == '/' {
name = strings.TrimRight(name, "/")
}
if v, ok := l.fm[name]; ok {
return &v, nil
}
for _, v := range l.fm {
if v.path == name {
if strings.HasPrefix(v.path, name) {
return createDirFile(name, l.fm), nil
}
}
return nil, ErrNotFound
return nil, os.ErrNotExist
}
// New{{.Suffix}}Loader returns a new AssetLoader for the {{.Suffix}} resources.
Expand Down

0 comments on commit 2b907c1

Please sign in to comment.