1. 新增安全响应头中间件强化请求安全性 2. 使用恒定时间比较修复API密钥验证时序漏洞 3. 新增限流器条目上限配置与自动清理逻辑 4. 优化CORS日志与客户端IP获取逻辑 5. 升级Go构建环境与基础镜像版本 6. 新增非root用户运行容器增强安全性
29 lines
733 B
Go
29 lines
733 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.CORS)
|
|
r.Use(middleware.SecurityHeaders)
|
|
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
|
|
}
|