This commit is contained in:
WJQSERVER 2024-10-20 17:48:31 +08:00
parent e5d941414e
commit aee81ba4fd
3 changed files with 7 additions and 7 deletions

View file

@ -6,7 +6,7 @@ import (
type Config struct {
Server ServerConfig
Page PageConfig
Pages PagesConfig
Log LogConfig
CORS CORSConfig
Auth AuthConfig
@ -20,7 +20,7 @@ type ServerConfig struct {
SizeLimit int `toml:"sizeLimit"`
}
type PageConfig struct {
type PagesConfig struct {
Enabled bool `toml:"enabled"`
StaticDir string `toml:"staticDir"`
}

View file

@ -3,7 +3,7 @@ host = "127.0.0.1"
port = 8080
sizeLimit = 131072000 # 125MB
[page]
[pages]
enabled = true
staticDir = "/data/www"

View file

@ -79,14 +79,14 @@ func init() {
setupApi(cfg, router)
if cfg.Page.Enabled {
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Page.StaticDir)
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Page.StaticDir)
if cfg.Pages.Enabled {
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir)
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir)
// 静态index页
router.StaticFile("/", indexPagePath)
// 静态favicon.ico
router.StaticFile("/favicon.ico", faviconPath)
} else if !cfg.Page.Enabled {
} else if !cfg.Pages.Enabled {
router.GET("/", func(c *gin.Context) {
c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.")
LogWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto)