diff --git a/api/conf/conf.go b/api/conf/conf.go index 6ea9af02de..2b26e5c821 100644 --- a/api/conf/conf.go +++ b/api/conf/conf.go @@ -36,7 +36,7 @@ const ( EnvDEV = "dev" EnvLOCAL = "local" - WebDir = "./html" + WebDir = "/html" ) var ( diff --git a/api/internal/route.go b/api/internal/route.go index a57e5c0e0a..dd0e54cd6d 100644 --- a/api/internal/route.go +++ b/api/internal/route.go @@ -49,9 +49,9 @@ func SetUpRouter() *gin.Engine { store := cookie.NewStore([]byte("secret")) r.Use(sessions.Sessions("session", store)) r.Use(filter.CORS(), filter.RequestId(), filter.RequestLogHandler(logger), filter.SchemaCheck(), filter.Authentication(), filter.RecoverHandler()) - r.Use(static.Serve("/", static.LocalFile(conf.WebDir, false))) + r.Use(static.Serve("/", static.LocalFile(conf.WorkDir + conf.WebDir, false))) r.NoRoute(func(c *gin.Context) { - c.File(fmt.Sprintf("%s/index.html", conf.WebDir)) + c.File(fmt.Sprintf("%s/index.html", conf.WorkDir + conf.WebDir)) }) factories := []handler.RegisterFactory{ diff --git a/api/test/shell/cli_test.sh b/api/test/shell/cli_test.sh index ad1568d2a8..0d46a56f6d 100755 --- a/api/test/shell/cli_test.sh +++ b/api/test/shell/cli_test.sh @@ -95,6 +95,26 @@ if [[ `grep -c "INFO" ./error.log` -eq '0' ]]; then exit 1 fi +# run on a different path +workDir=$(pwd) +rm -rf html +mkdir html +cd html +echo "hi~" >> index.html +APISIX_API_WORKDIR=$workDir $workDir/manager-api & +sleep 5 + +res=$(curl http://127.0.0.1:9000) +pkill -f manager-api + +if [[ $res == "404 page not found" ]]; then + echo "failed: manager-api cant run on a different path" + exit 1 +fi + +cd - +rm -rf html +clean_up # test start info