This commit is contained in:
Sakurasan
2025-04-16 23:39:56 +08:00
parent 2360e7d2bf
commit d4cbc27a77
6 changed files with 80 additions and 27 deletions

View File

@@ -2,7 +2,9 @@ package main
import (
"context"
"embed"
"fmt"
"io/fs"
"log"
"net/http"
"opencatd-open/middleware"
@@ -18,6 +20,9 @@ import (
"github.com/gin-gonic/gin"
)
//go:embed dist/*
var web embed.FS
func main() {
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
@@ -53,6 +58,7 @@ func main() {
r := gin.Default()
r.Use(middleware.CORS())
teamGroup := r.Group("/1")
teamGroup.Use(team.AuthMiddleware())
{
@@ -122,13 +128,24 @@ func main() {
}
v1 := r.Group("/v1")
v1.Use(middleware.AuthLLM(store.DB))
v1.Use(middleware.AuthLLM(db))
{
// v1.POST("/v2/*proxypath", router.HandleProxy)
v1.POST("/v1/*proxypath", proxy.HandleProxy)
// v1.GET("/models", dashboard.HandleModels)
}
idxFS, err := fs.Sub(web, "dist")
if err != nil {
panic(err)
}
r.GET("/", gin.WrapH(http.FileServer(http.FS(idxFS))))
assetsFS, err := fs.Sub(web, "dist/assets")
if err != nil {
panic(err)
}
r.GET("/assets/*filepath", gin.WrapH(http.StripPrefix("/assets/", http.FileServer(http.FS(assetsFS)))))
srv := &http.Server{
Addr: ":8080",
Handler: r,