mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
Update middleware.go
This commit is contained in:
parent
72739fb07f
commit
b8d5d03572
1 changed files with 44 additions and 62 deletions
|
@ -10,7 +10,6 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func authRequired() gin.HandlerFunc {
|
||||
|
@ -65,20 +64,3 @@ func mustFS(dir string) (serverFileSystem static.ServeFileSystem) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
// tryStatic Static returns a middleware handler that serves static files in the given directory.
|
||||
func tryStatic(urlPrefix string, fs static.ServeFileSystem) gin.HandlerFunc {
|
||||
fileserver := http.FileServer(fs)
|
||||
if urlPrefix != "" {
|
||||
fileserver = http.StripPrefix(urlPrefix, fileserver)
|
||||
}
|
||||
return func(c *gin.Context) {
|
||||
if fs.Exists(urlPrefix, c.Request.URL.Path) {
|
||||
fileserver.ServeHTTP(c.Writer, c.Request)
|
||||
if strings.Contains(c.Request.URL.Path, ".js") {
|
||||
c.Writer.Header().Set("content-type", "application/javascript")
|
||||
}
|
||||
c.Abort()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue