🎨 优化模型配置 && 新增apikey功能 && 完善通用接口
This commit is contained in:
@@ -57,15 +57,9 @@ func Routers() *gin.Engine {
|
||||
|
||||
systemRouter := router.RouterGroupApp.System
|
||||
exampleRouter := router.RouterGroupApp.Example
|
||||
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
||||
// VUE_APP_BASE_API = /
|
||||
// VUE_APP_BASE_PATH = http://localhost
|
||||
// 然后执行打包命令 npm run build。在打开下面3行注释
|
||||
// Router.StaticFile("/favicon.ico", "./dist/favicon.ico")
|
||||
// Router.Static("/assets", "./dist/assets") // dist里面的静态资源
|
||||
// Router.StaticFile("/", "./dist/index.html") // 前端网页入口页面
|
||||
|
||||
Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)}) // Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
|
||||
// 静态文件服务
|
||||
Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)})
|
||||
// 跨域,如需跨域可以打开下面的注释
|
||||
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
|
||||
// Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
|
||||
@@ -124,8 +118,41 @@ func Routers() *gin.Engine {
|
||||
// 注册业务路由
|
||||
initBizRouter(PrivateGroup, PublicGroup)
|
||||
|
||||
// 前端静态文件服务(放在最后,作为兜底路由)
|
||||
setupFrontendRoutes(Router)
|
||||
|
||||
global.GVA_ROUTERS = Router.Routes()
|
||||
|
||||
global.GVA_LOG.Info("router register success")
|
||||
return Router
|
||||
}
|
||||
|
||||
// setupFrontendRoutes 配置前端静态文件路由
|
||||
func setupFrontendRoutes(router *gin.Engine) {
|
||||
// 检查 dist 目录是否存在
|
||||
if _, err := os.Stat("./dist"); os.IsNotExist(err) {
|
||||
global.GVA_LOG.Warn("前端 dist 目录不存在,跳过前端路由配置")
|
||||
return
|
||||
}
|
||||
|
||||
// 静态资源目录
|
||||
router.Static("/assets", "./dist/assets")
|
||||
router.StaticFile("/favicon.ico", "./dist/favicon.ico")
|
||||
|
||||
// SPA 路由处理:所有非 API 请求都返回 index.html
|
||||
router.NoRoute(func(c *gin.Context) {
|
||||
path := c.Request.URL.Path
|
||||
// 如果是 API 请求,返回 404
|
||||
if strings.HasPrefix(path, global.GVA_CONFIG.System.RouterPrefix) {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"code": 404,
|
||||
"msg": "接口不存在",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 其他请求返回前端页面
|
||||
c.File("./dist/index.html")
|
||||
})
|
||||
|
||||
global.GVA_LOG.Info("前端静态文件路由配置成功")
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ func initBizRouter(routers ...*gin.RouterGroup) {
|
||||
|
||||
// 注册 AI 代理路由
|
||||
appRouter := router.RouterGroupApp.App
|
||||
appRouter.InitAiProxyRouter(publicGroup) // AI 代理接口(公开)
|
||||
appRouter.InitAiPresetRouter(privateGroup) // 预设管理(需要登录)
|
||||
appRouter.InitAiProviderRouter(privateGroup) // 提供商管理(需要登录)
|
||||
appRouter.InitAiPresetBindingRouter(privateGroup) // 绑定管理(需要登录)
|
||||
appRouter.InitAiProxyRouter(publicGroup) // AI 代理接口(公开)
|
||||
appRouter.InitAiPresetRouter(privateGroup) // 预设管理(需要登录)
|
||||
appRouter.InitAiProviderRouter(privateGroup) // 提供商管理(需要登录)
|
||||
appRouter.InitAiApiKeyRouter(privateGroup) // API密钥管理(需要登录)
|
||||
appRouter.InitAiModelRouter(privateGroup) // 模型管理(需要登录)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user