Browse Source

Serve index.html file of any folder

Vova Tkach 6 years ago
parent
commit
9f6f875573
2 changed files with 16 additions and 0 deletions
  1. 15 0
      engine/wrapper/static.go
  2. 1 0
      hosts/localhost/htdocs/admin/index.html

+ 15 - 0
engine/wrapper/static.go

@@ -88,6 +88,21 @@ func (this *Wrapper) staticFile() bool {
 				return false
 			}
 			if st.Mode().IsDir() {
+				if file[len(file)-1] == '/' {
+					fi, err := os.Open(this.DirVHostHome + "/htdocs" + file + "/index.html")
+					if err == nil {
+						defer fi.Close()
+						sti, err := os.Stat(this.DirVHostHome + "/htdocs" + file + "/index.html")
+						if err != nil {
+							return false
+						}
+						if sti.Mode().IsDir() {
+							return false
+						}
+						http.ServeFile(*this.W, this.R, this.DirVHostHome+"/htdocs"+file+"/index.html")
+						return true
+					}
+				}
 				return false
 			}
 			http.ServeFile(*this.W, this.R, this.DirVHostHome+"/htdocs"+file)

+ 1 - 0
hosts/localhost/htdocs/admin/index.html

@@ -0,0 +1 @@
+index