diff --git a/service/static.go b/service/static.go index e58aaff4..19443041 100644 --- a/service/static.go +++ b/service/static.go @@ -54,7 +54,13 @@ func (d Dir) Open(name string) (http.File, error) { dir = "." } - fullName := filepath.Join(dir, filepath.FromSlash(path.Clean("/"+name))) + name = path.Clean("/" + name) + fullName := filepath.Join(dir, filepath.FromSlash(name)) + if isPWA() { + if filepath.Ext(fullName) == "" && fullName != dir { + fullName = filepath.Join(dir, "index.html") + } + } // Close dir views Disable directory listing stat, err := os.Stat(fullName) @@ -101,6 +107,14 @@ func mapOpenError(originalErr error, name string, sep rune, stat func(string) (f return originalErr } +// rewrite path +func isPWA() bool { + if share.App.Static == nil { + return false + } + return share.App.Static.PWA +} + // SetupAdmin setup admin static root func adminRoot() (string, int) { if AdminRoot != "" { diff --git a/share/types.go b/share/types.go index 8c88a6fa..97241c4d 100644 --- a/share/types.go +++ b/share/types.go @@ -81,9 +81,15 @@ type AppInfo struct { Option map[string]interface{} `json:"option,omitempty"` XGen string `json:"xgen,omitempty"` AdminRoot string `json:"adminRoot,omitempty"` + Static *Static `json:"public,omitempty"` Optional map[string]interface{} `json:"optional,omitempty"` } +// Static setting +type Static struct { + PWA bool `json:"pwa,omitempty"` +} + // AppStorage 应用存储 type AppStorage struct { Default string `json:"default"`