From 6a9d1e0fe50f9c86381ea46477f07843f75770e1 Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Wed, 4 Oct 2023 11:46:44 +0800 Subject: [PATCH] Add frontendBaseDir --- conf/app.conf | 7 ++++--- routers/static_filter.go | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/conf/app.conf b/conf/app.conf index ac81c7fa..24500f29 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -8,12 +8,12 @@ dbName = casdoor tableNamePrefix = showSql = false redisEndpoint = -defaultStorageProvider = +defaultStorageProvider = isCloudIntranet = false authState = "casdoor" socks5Proxy = "127.0.0.1:10808" verificationCodeTimeout = 10 -initScore = 2000 +initScore = 0 logPostOnly = true origin = staticBaseUrl = "https://cdn.casbin.org" @@ -24,4 +24,5 @@ radiusServerPort = 1812 radiusSecret = "secret" quota = {"organization": -1, "user": -1, "application": -1, "provider": -1} logConfig = {"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"} -initDataFile = "./init_data.json" \ No newline at end of file +initDataFile = "./init_data.json" +frontendBaseDir = "../casdoor" \ No newline at end of file diff --git a/routers/static_filter.go b/routers/static_filter.go index 39d03284..0d649879 100644 --- a/routers/static_filter.go +++ b/routers/static_filter.go @@ -33,8 +33,19 @@ var ( oldStaticBaseUrl = "https://cdn.casbin.org" newStaticBaseUrl = conf.GetConfigString("staticBaseUrl") enableGzip = conf.GetConfigBool("enableGzip") + frontendBaseDir = conf.GetConfigString("frontendBaseDir") ) +func getWebBuildFolder() string { + path := "web/build" + if util.FileExist(filepath.Join(path, "index.html")) || frontendBaseDir == "" { + return path + } + + path = filepath.Join(frontendBaseDir, "web/build") + return path +} + func StaticFilter(ctx *context.Context) { urlPath := ctx.Request.URL.Path @@ -49,7 +60,8 @@ func StaticFilter(ctx *context.Context) { return } - path := "web/build" + webBuildFolder := getWebBuildFolder() + path := webBuildFolder if urlPath == "/" { path += "/index.html" } else { @@ -57,7 +69,7 @@ func StaticFilter(ctx *context.Context) { } if !util.FileExist(path) { - path = "web/build/index.html" + path = webBuildFolder + "/index.html" } if !util.FileExist(path) { dir, err := os.Getwd()