fix: 🐛 路由必须在中间件之后注册

main
熊二 2 years ago
parent 963d4aabf3
commit bf7064f992
  1. 8
      main.go

@ -12,7 +12,7 @@ import (
)
func main() {
app.ConfigLogger("debug.log", app.LogWhenMinute)
app.ConfigLogger("./tmp/debug.log", app.LogWhenMinute)
app.ConfigGormDB()
r := chi.NewRouter()
@ -38,9 +38,6 @@ func main() {
// Please see _example/main.go for other more, or read the library code.
r.Use(httprate.LimitByIP(100, 1*time.Minute))
// mounting net/http/pprof
r.Mount("/debug", middleware.Profiler())
// 允许跨域
// see: https://developer.github.com/v3/#cross-origin-resource-sharing
r.Use(cors.Handler(cors.Options{
@ -54,6 +51,9 @@ func main() {
MaxAge: 300, // Maximum value not ignored by any of major browsers
}))
// mounting net/http/pprof
r.Mount("/debug", middleware.Profiler())
app.RegisterRoutes(r)
if err := http.ListenAndServe(":3000", r); err != nil {

Loading…
Cancel
Save