Bläddra i källkod

Add vue history mode support for default frontend.

zry 4 år sedan
förälder
incheckning
df1327e9f8

+ 25 - 6
defaultFrontend/server.go

@@ -80,25 +80,44 @@ func ForbiddenHandler(ctx *gin.Context) {
 func StaticFilesHandler(url string, ctx *gin.Context) {
 	finf, err := StaticFileSystem.Open(path.Clean(url))
 	if os.IsNotExist(err) {
-		NotFoundHandler(ctx)
-		return
+		if ConfigData.CommonConfig.VueHistoryMode {
+			VueHistoryModeHandler(ctx)
+			return
+		} else {
+			NotFoundHandler(ctx)
+			return
+		}
 	}
 	fst, err := finf.Stat()
 	if err != nil {
-		NotFoundHandler(ctx)
-		return
+		if ConfigData.CommonConfig.VueHistoryMode {
+			VueHistoryModeHandler(ctx)
+			return
+		} else {
+			NotFoundHandler(ctx)
+			return
+		}
 	}
 	if fst.IsDir() {
 		_, err := StaticFileSystem.Open(path.Clean(path.Join(url, "index.html")))
 		if os.IsNotExist(err) {
-			ForbiddenHandler(ctx)
-			return
+			if ConfigData.CommonConfig.VueHistoryMode {
+				VueHistoryModeHandler(ctx)
+				return
+			} else {
+				ForbiddenHandler(ctx)
+				return
+			}
 		}
 	}
 	ctx.Request.URL.Path = url
 	FileServer.ServeHTTP(ctx.Writer, ctx.Request)
 }
 
+func VueHistoryModeHandler(ctx *gin.Context) {
+	http.ServeFile(ctx.Writer, ctx.Request, path.Join(WWWRootPath, "index.html"))
+}
+
 func APIReverseProxy(context *gin.Context) {
 	if !ConfigData.CommonConfig.IsBackendProxyEnable {
 		NotFoundHandler(context)

+ 1 - 0
defaultFrontend/yamldef.go

@@ -11,6 +11,7 @@ type CommonConfigYAML struct {
 	RedirectURL          string `yaml:"redirect_url"`
 	IsBackendProxyEnable bool   `yaml:"backend_proxy_enable"`
 	UseGZip              bool   `yaml:"enable_gzip"`
+	VueHistoryMode       bool   `yaml:"vue_history_mode"`
 }
 
 type LogConfigYAML struct {

BIN
dist/rel/zDWSIFrontend_linux


+ 2 - 0
dist/rel/zdwsi.frontend.config.default.yaml

@@ -10,6 +10,8 @@ common:
   backend_proxy_enable: true
   # 'true' for enable gzip compression
   enable_gzip: true
+  # 'true' for enable vue history mode support
+  vue_history_mode: true
 # config for log
 log:
   # 'true' for enable access log, 'false' for disable access log