Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a http function to serve assets
  • Loading branch information
lunny committed May 29, 2021
commit 0fba10663a06afc65aa90617114e94546a0c7c1c
38 changes: 18 additions & 20 deletions modules/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ type Options struct {
}

// AssetsHandler implements the static handler for serving custom or original assets.
func AssetsHandler(opts *Options) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
var custPath = filepath.Join(setting.CustomPath, "public")
if !filepath.IsAbs(custPath) {
custPath = filepath.Join(setting.AppWorkPath, custPath)
}
func AssetsHandler(opts *Options) func(resp http.ResponseWriter, req *http.Request) {
var custPath = filepath.Join(setting.CustomPath, "public")
if !filepath.IsAbs(custPath) {
custPath = filepath.Join(setting.AppWorkPath, custPath)
}

if !filepath.IsAbs(opts.Directory) {
opts.Directory = filepath.Join(setting.AppWorkPath, opts.Directory)
}
if !filepath.IsAbs(opts.Directory) {
opts.Directory = filepath.Join(setting.AppWorkPath, opts.Directory)
}

return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
// custom files
if opts.handle(resp, req, http.Dir(custPath), opts.Prefix) {
return
}
return func(resp http.ResponseWriter, req *http.Request) {
// custom files
if opts.handle(resp, req, http.Dir(custPath), opts.Prefix) {
return
}

// internal files
if opts.handle(resp, req, fileSystem(opts.Directory), opts.Prefix) {
return
}
// internal files
if opts.handle(resp, req, fileSystem(opts.Directory), opts.Prefix) {
return
}

resp.WriteHeader(404)
})
resp.WriteHeader(404)
}
}

Expand Down