mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-30 07:06:38 +08:00
* ♻️ refactor: move file directory * ♻️ refactor: move file directory * ♻️ refactor: support multiple config methods * 🔥 del: remove unused code * 💩 refactor: Refactor channel management and synchronization * 💄 improve: add channel website * ✨ feat: allow recording 0 consumption
29 lines
769 B
Go
29 lines
769 B
Go
package router
|
|
|
|
import (
|
|
"embed"
|
|
"net/http"
|
|
"one-api/controller"
|
|
"one-api/middleware"
|
|
"strings"
|
|
|
|
"github.com/gin-contrib/gzip"
|
|
"github.com/gin-contrib/static"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func SetWebRouter(router *gin.Engine, buildFS embed.FS, indexPage []byte) {
|
|
router.Use(gzip.Gzip(gzip.DefaultCompression))
|
|
router.Use(middleware.GlobalWebRateLimit())
|
|
router.Use(middleware.Cache())
|
|
router.Use(static.Serve("/", static.EmbedFolder(buildFS, "web/build")))
|
|
router.NoRoute(func(c *gin.Context) {
|
|
if strings.HasPrefix(c.Request.RequestURI, "/v1") || strings.HasPrefix(c.Request.RequestURI, "/api") {
|
|
controller.RelayNotFound(c)
|
|
return
|
|
}
|
|
c.Header("Cache-Control", "no-cache")
|
|
c.Data(http.StatusOK, "text/html; charset=utf-8", indexPage)
|
|
})
|
|
}
|