1. 调整CORS中间件挂载位置,重构CORS处理逻辑 2. 重写IP获取逻辑,增加私有网络IP信任校验 3. 优化日志中间件,移除/health接口单独日志逻辑 4. 改进API密钥未配置时的提示信息 5. 重构volcano TTS调用,新增voice参数支持 6. 优化请求体过大错误处理 7. 完善统计服务,修复环形缓冲区遍历逻辑,新增去重错误日志功能
30 lines
774 B
Go
30 lines
774 B
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/volcano-tts/tts-api/controller"
|
|
"github.com/volcano-tts/tts-api/middleware"
|
|
)
|
|
|
|
func Setup() *mux.Router {
|
|
r := mux.NewRouter()
|
|
|
|
r.Use(middleware.SecurityHeaders)
|
|
r.Use(middleware.RateLimit)
|
|
r.Use(middleware.ConcurrencyLimit)
|
|
r.Use(middleware.Logger)
|
|
|
|
r.HandleFunc("/v1/audio/speech", controller.OpenaiTTSHandler).Methods("POST", "OPTIONS")
|
|
r.HandleFunc("/health", controller.HealthHandler).Methods("GET")
|
|
r.HandleFunc("/dashboard", func(w http.ResponseWriter, r *http.Request) {
|
|
http.ServeFile(w, r, "health.html")
|
|
}).Methods("GET")
|
|
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, "/dashboard", http.StatusFound)
|
|
}).Methods("GET")
|
|
|
|
return r
|
|
}
|