Skip to content

Commit

Permalink
feta: allow use -d to specify dist path
Browse files Browse the repository at this point in the history
  • Loading branch information
soxft committed Jun 26, 2022
1 parent 8f0bf16 commit 7c1a92b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
11 changes: 10 additions & 1 deletion ENTRYPOINT.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ if [ -n "$API_SERVER" ];then
fi

# redis地址
sed -i "s/Address: 127.0.0.1:6379/Address: redis:6379/g" config.yaml
if [ -n "$REDIS_ADDR" ];then
sed -i "s/Address: 127.0.0.1:6379/Address: $REDIS_ADDR/g" config.yaml
else
sed -i "s/Address: 127.0.0.1:6379/Address: redis:6379/g" config.yaml
fi

# redis 密码
if [ -n "$REDIS_PWD" ];then
sed -i "s/Password:/Password: $REDIS_PWD/g" config.yaml
fi

# 是否开启debug模式
if [ -n "$DEBUG_ENABLE" ];then
Expand Down
2 changes: 1 addition & 1 deletion app/middleware/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", config.Web.Cors)
c.Header("Server", "busuanzi-by-xcsoft/2.7.2")
c.Header("Server", "busuanzi-by-xcsoft/2.7.3")
if c.Request.Method == "OPTIONS" {
c.Header("Access-Control-Allow-Methods", "GET, POST, HEAD, OPTIONS")
c.Header("Access-Control-Allow-Headers", "x-bsz-referer, Authorization")
Expand Down
13 changes: 9 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import (
)

var (
C *Config
Redis RedisConfig
Web WebConfig
Bsz BszConfig
C *Config
Redis RedisConfig
Web WebConfig
Bsz BszConfig
)

var (
configPath string
DistPath string
)

func init() {
// get config file path
flag.StringVar(&configPath, "c", "config.yaml", "config path")
flag.StringVar(&DistPath, "d", "dist", "dist path")
flag.Parse()

data, err := ioutil.ReadFile(configPath)
Expand Down
3 changes: 2 additions & 1 deletion process/webutil/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webutil
import (
"busuanzi/app/controller"
"busuanzi/app/middleware"
"busuanzi/config"
"github.com/gin-gonic/gin"
)

Expand All @@ -15,7 +16,7 @@ func initRoute(r *gin.Engine) {
{
static.Use(middleware.Cache())
static.GET("/", controller.Index)
static.StaticFile("/js", "dist/busuanzi.js")
static.StaticFile("/js", config.DistPath+"/busuanzi.js")
}
r.NoRoute(middleware.Cache(), controller.Index)
}
Expand Down
2 changes: 1 addition & 1 deletion process/webutil/webutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func Init() {
}
r.Use(gin.Recovery())
r.Use(middleware.Cors())
r.LoadHTMLFiles("dist/index.html")
r.LoadHTMLFiles(config.DistPath + "/index.html")

// routers
initRoute(r)
Expand Down

0 comments on commit 7c1a92b

Please sign in to comment.