Skip to content

Commit

Permalink
从配置读取静态文件路径
Browse files Browse the repository at this point in the history
  • Loading branch information
xiamingyu committed Dec 12, 2024
1 parent b4cff3c commit a4b14d3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion api/server/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func InstallRouters(o *options.Options) {
}

install(o, fs...)
o.HttpEngine.Use(static.Serve("/", static.LocalFile("./static", true)))
o.HttpEngine.Use(static.Serve("/", static.LocalFile(o.ComponentConfig.Default.StaticFiles,
true)))

// 启动健康检查
o.HttpEngine.GET("/healthz", func(c *gin.Context) { c.String(http.StatusOK, "ok") })
// 启动 APIs 服务
Expand Down
2 changes: 2 additions & 0 deletions cmd/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type DefaultOptions struct {
AutoMigrate bool `yaml:"auto_migrate"`

logutil.LogOptions `yaml:",inline"`

StaticFiles string `yaml:"static_files"`
}

func (o DefaultOptions) Valid() error {
Expand Down
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ default:
# 日志的格式,可选 text 和 json
log_format: json
log_level: info
# 静态文件路径
static_files: ./static

# 数据库地址信息
mysql:
Expand Down
Empty file removed static/_balnk
Empty file.
4 changes: 4 additions & 0 deletions static1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"url": "http://127.0.0.1:8090",
"watchUrl": "http://127.0.0.1:8090"
}

0 comments on commit a4b14d3

Please sign in to comment.