Merge pull request #363 from trheyi/main

[add] public dir  PWA  support
This commit is contained in:
Max 2023-04-11 21:25:28 +08:00 committed by GitHub
commit 57e8bb834f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -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 != "" {

View file

@ -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"`