mirror of
https://github.com/acepanel/panel.git
synced 2026-02-05 02:07:18 +08:00
31 lines
899 B
Go
31 lines
899 B
Go
package middleware
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gin-contrib/static"
|
|
"github.com/goravel/framework/contracts/http"
|
|
"github.com/goravel/gin"
|
|
|
|
"panel/app/services"
|
|
)
|
|
|
|
func Static() http.Middleware {
|
|
return func(ctx http.Context) {
|
|
// 自动纠正 URL 格式
|
|
if ctx.Request().Path() == services.NewSettingImpl().Get("entrance", "/") && ctx.Request().Path() != "/" {
|
|
// ctx.Response().Redirect(http.StatusFound, ctx.Request().Path()+"/")
|
|
ctx.Response().Writer().WriteHeader(http.StatusFound)
|
|
_, err := ctx.Response().Writer().Write([]byte(fmt.Sprintf(`<html><head><meta http-equiv="refresh" content="0;url=%s/"></head></html>`, ctx.Request().Path())))
|
|
if err != nil {
|
|
return
|
|
}
|
|
ctx.Response().Flush()
|
|
return
|
|
}
|
|
|
|
static.Serve(services.NewSettingImpl().Get("entrance", "/"), static.LocalFile("public", false))(ctx.(*gin.Context).Instance())
|
|
ctx.Request().Next()
|
|
}
|
|
}
|