Bladeren bron

Fix .js mime issues in windows

0xJacky 3 jaren geleden
bovenliggende
commit
8a7f7672d9

+ 1 - 1
frontend/src/layouts/FooterLayout.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="footer center">
-        Copyright © 2020 - {{ thisYear }} 0xJacky
+        Copyright © 2020 - {{ thisYear }} Nginx UI
     </div>
 </template>
 

+ 3 - 2
frontend/src/views/other/About.vue

@@ -7,7 +7,8 @@
         <p>Yet another WebUI for Nginx</p>
         <p>Version: {{ version }} ({{ build_id }})</p>
         <h3>项目组</h3>
-        <p>Designer:<a href="https://jackyu.cn/">@0xJacky</a></p>
+        <p><a href="https://jackyu.cn/">@0xJacky</a></p>
+        <p><a href="https://blog.kugeek.com/">@Hintay</a></p>
         <h3>技术栈</h3>
         <p>Go</p>
         <p>Gin</p>
@@ -15,7 +16,7 @@
         <p>Websocket</p>
         <h3>开源协议</h3>
         <p>GNU General Public License v2.0</p>
-        <p>Copyright © 2020 - {{ this_year }} 0xJacky </p>
+        <p>Copyright © 2020 - {{ this_year }} Nginx UI </p>
     </a-card>
 </template>
 

+ 1 - 1
frontend/version.json

@@ -1 +1 @@
-{"version":"1.1.0","build_id":4,"total_build":21}
+{"version":"1.1.0","build_id":5,"total_build":22}

+ 26 - 1
go.mod

@@ -1,6 +1,6 @@
 module github.com/0xJacky/Nginx-UI
 
-go 1.16
+go 1.17
 
 require (
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
@@ -21,3 +21,28 @@ require (
 	gorm.io/driver/sqlite v1.1.4
 	gorm.io/gorm v1.21.14
 )
+
+require (
+	github.com/StackExchange/wmi v1.2.1 // indirect
+	github.com/cenkalti/backoff/v4 v4.1.0 // indirect
+	github.com/gin-contrib/sse v0.1.0 // indirect
+	github.com/go-ole/go-ole v1.2.5 // indirect
+	github.com/golang/protobuf v1.3.4 // indirect
+	github.com/jinzhu/inflection v1.0.0 // indirect
+	github.com/jinzhu/now v1.1.2 // indirect
+	github.com/json-iterator/go v1.1.9 // indirect
+	github.com/leodido/go-urn v1.2.0 // indirect
+	github.com/mattn/go-isatty v0.0.12 // indirect
+	github.com/mattn/go-sqlite3 v1.14.5 // indirect
+	github.com/miekg/dns v1.1.40 // indirect
+	github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+	github.com/modern-go/reflect2 v1.0.1 // indirect
+	github.com/tklauser/go-sysconf v0.3.7 // indirect
+	github.com/tklauser/numcpus v0.2.3 // indirect
+	github.com/ugorji/go/codec v1.1.7 // indirect
+	golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect
+	golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
+	golang.org/x/text v0.3.4 // indirect
+	gopkg.in/square/go-jose.v2 v2.5.1 // indirect
+	gopkg.in/yaml.v2 v2.4.0 // indirect
+)

+ 84 - 0
server/router/middleware.go

@@ -0,0 +1,84 @@
+package router
+
+import (
+    "encoding/base64"
+    "github.com/0xJacky/Nginx-UI/frontend"
+    "github.com/0xJacky/Nginx-UI/server/model"
+    "github.com/gin-contrib/static"
+    "github.com/gin-gonic/gin"
+    "io/fs"
+    "log"
+    "net/http"
+    "path"
+    "strings"
+)
+
+func authRequired() gin.HandlerFunc {
+    return func(c *gin.Context) {
+        token := c.GetHeader("Authorization")
+        if token == "" {
+            tmp, _ := base64.StdEncoding.DecodeString(c.Query("token"))
+            token = string(tmp)
+            if token == "" {
+                c.JSON(http.StatusForbidden, gin.H{
+                    "message": "auth fail",
+                })
+                c.Abort()
+                return
+            }
+        }
+
+        n := model.CheckToken(token)
+
+        if n < 1 {
+            c.JSON(http.StatusForbidden, gin.H{
+                "message": "auth fail",
+            })
+            c.Abort()
+            return
+        }
+        c.Next()
+    }
+}
+
+type serverFileSystemType struct {
+    http.FileSystem
+}
+
+func (f serverFileSystemType) Exists(prefix string, _path string) bool {
+    _, err := f.Open(path.Join(prefix, _path))
+    return err == nil
+}
+
+func mustFS(dir string) (serverFileSystem static.ServeFileSystem) {
+
+    sub, err := fs.Sub(frontend.DistFS, path.Join("dist", dir))
+
+    if err != nil {
+        log.Println(err)
+        return
+    }
+
+    serverFileSystem = serverFileSystemType{
+        http.FS(sub),
+    }
+
+    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()
+        }
+    }
+}

+ 1 - 60
server/router/routers.go

@@ -2,78 +2,19 @@ package router
 
 import (
 	"bufio"
-	"encoding/base64"
-	"github.com/0xJacky/Nginx-UI/frontend"
 	api2 "github.com/0xJacky/Nginx-UI/server/api"
-	"github.com/0xJacky/Nginx-UI/server/model"
-	"github.com/gin-contrib/static"
 	"github.com/gin-gonic/gin"
-	"io/fs"
-	"log"
 	"net/http"
-	"path/filepath"
 	"strings"
 )
 
-func authRequired() gin.HandlerFunc {
-	return func(c *gin.Context) {
-		token := c.GetHeader("Authorization")
-		if token == "" {
-			tmp, _ := base64.StdEncoding.DecodeString(c.Query("token"))
-			token = string(tmp)
-			if token == "" {
-				c.JSON(http.StatusForbidden, gin.H{
-					"message": "auth fail",
-				})
-				c.Abort()
-				return
-			}
-		}
-
-		n := model.CheckToken(token)
-
-		if n < 1 {
-			c.JSON(http.StatusForbidden, gin.H{
-				"message": "auth fail",
-			})
-			c.Abort()
-			return
-		}
-		c.Next()
-	}
-}
-
-type serverFileSystemType struct {
-	http.FileSystem
-}
-
-func (f serverFileSystemType) Exists(prefix string, path string) bool {
-	_, err := f.Open(filepath.Join(prefix, path))
-	return err == nil
-}
-
-func mustFS(dir string) (serverFileSystem static.ServeFileSystem) {
-
-	sub, err := fs.Sub(frontend.DistFS, filepath.Join("dist", dir))
-
-	if err != nil {
-		log.Println(err)
-	}
-
-	serverFileSystem = serverFileSystemType{
-		http.FS(sub),
-	}
-
-	return
-}
-
 func InitRouter() *gin.Engine {
 	r := gin.New()
 	r.Use(gin.Logger())
 
 	r.Use(gin.Recovery())
 
-	r.Use(static.Serve("/", mustFS("")))
+	r.Use(tryStatic("/", mustFS("")))
 
 	r.NoRoute(func(c *gin.Context) {
 		accept := c.Request.Header.Get("Accept")

+ 33 - 32
server/tool/nginx.go

@@ -1,52 +1,53 @@
 package tool
 
 import (
-    "errors"
-    "log"
-    "os/exec"
-    "path/filepath"
-    "regexp"
-    "strings"
+	"errors"
+	"log"
+	"os/exec"
+	"path/filepath"
+	"regexp"
+	"strings"
 )
 
 func TestNginxConf(filePath string) error {
-    out, err := exec.Command("nginx", "-t").CombinedOutput()
-    if err != nil {
-        log.Println(err)
-    }
-    output := string(out)
-    log.Println(output)
-    if strings.Contains(output, "failed") {
-        return errors.New(output)
-    }
-    return nil
+	out, err := exec.Command("nginx", "-t").CombinedOutput()
+	if err != nil {
+		log.Println(err)
+	}
+	output := string(out)
+	log.Println(output)
+	if strings.Contains(output, "failed") {
+		return errors.New(output)
+	}
+	return nil
 }
 
 func ReloadNginx() string {
-    out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
+	out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
 
-    if err != nil {
-        log.Println(err)
-    }
+	if err != nil {
+		log.Println(err)
+	}
 
-    output := string(out)
-    log.Println(output)
+	output := string(out)
+	log.Println(output)
 
-    return output
+	return output
 }
 
 func GetNginxConfPath(dir string) string {
-    out, err := exec.Command("nginx", "-V").CombinedOutput()
-    if err != nil {
-        log.Fatal(err)
-    }
-    // fmt.Printf("%s\n", out)
+	out, err := exec.Command("nginx", "-V").CombinedOutput()
+	if err != nil {
+		log.Println(err)
+		return ""
+	}
+	// fmt.Printf("%s\n", out)
 
-    r, _ := regexp.Compile("--conf-path=(.*)/(.*.conf)")
+	r, _ := regexp.Compile("--conf-path=(.*)/(.*.conf)")
 
-    confPath := r.FindStringSubmatch(string(out))[1]
+	confPath := r.FindStringSubmatch(string(out))[1]
 
-    // fmt.Println(confPath)
+	// fmt.Println(confPath)
 
-    return filepath.Join(confPath, dir)
+	return filepath.Join(confPath, dir)
 }