This commit is contained in:
WJQSERVER 2024-10-20 17:39:27 +08:00
parent c50f23c399
commit e5d941414e
11 changed files with 51 additions and 9 deletions

18
main.go
View file

@ -75,13 +75,23 @@ func init() {
gin.SetMode(gin.ReleaseMode)
router = gin.Default()
router.UseH2C = true
setupApi(cfg, router)
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", c.ClientIP(), c.Request.UserAgent(), c.Request.Method)
})
if cfg.Page.Enabled {
indexPagePath := fmt.Sprintf("%s/index.html", cfg.Page.StaticDir)
faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Page.StaticDir)
// 静态index页
router.StaticFile("/", indexPagePath)
// 静态favicon.ico
router.StaticFile("/favicon.ico", faviconPath)
} else if !cfg.Page.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)
})
}
// 未匹配路由处理
router.NoRoute(func(c *gin.Context) {