Add frontendBaseDir

This commit is contained in:
Yang Luo 2023-10-04 11:46:44 +08:00
parent 938e8e2699
commit 6a9d1e0fe5
2 changed files with 18 additions and 5 deletions

View File

@ -13,7 +13,7 @@ isCloudIntranet = false
authState = "casdoor" authState = "casdoor"
socks5Proxy = "127.0.0.1:10808" socks5Proxy = "127.0.0.1:10808"
verificationCodeTimeout = 10 verificationCodeTimeout = 10
initScore = 2000 initScore = 0
logPostOnly = true logPostOnly = true
origin = origin =
staticBaseUrl = "https://cdn.casbin.org" staticBaseUrl = "https://cdn.casbin.org"
@ -25,3 +25,4 @@ radiusSecret = "secret"
quota = {"organization": -1, "user": -1, "application": -1, "provider": -1} quota = {"organization": -1, "user": -1, "application": -1, "provider": -1}
logConfig = {"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"} logConfig = {"filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"}
initDataFile = "./init_data.json" initDataFile = "./init_data.json"
frontendBaseDir = "../casdoor"

View File

@ -33,8 +33,19 @@ var (
oldStaticBaseUrl = "https://cdn.casbin.org" oldStaticBaseUrl = "https://cdn.casbin.org"
newStaticBaseUrl = conf.GetConfigString("staticBaseUrl") newStaticBaseUrl = conf.GetConfigString("staticBaseUrl")
enableGzip = conf.GetConfigBool("enableGzip") 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) { func StaticFilter(ctx *context.Context) {
urlPath := ctx.Request.URL.Path urlPath := ctx.Request.URL.Path
@ -49,7 +60,8 @@ func StaticFilter(ctx *context.Context) {
return return
} }
path := "web/build" webBuildFolder := getWebBuildFolder()
path := webBuildFolder
if urlPath == "/" { if urlPath == "/" {
path += "/index.html" path += "/index.html"
} else { } else {
@ -57,7 +69,7 @@ func StaticFilter(ctx *context.Context) {
} }
if !util.FileExist(path) { if !util.FileExist(path) {
path = "web/build/index.html" path = webBuildFolder + "/index.html"
} }
if !util.FileExist(path) { if !util.FileExist(path) {
dir, err := os.Getwd() dir, err := os.Getwd()