udemy-go-microservices/broker-service/cmd/api/routes.go

31 lines
712 B
Go
Raw Normal View History

2024-08-28 07:28:34 +00:00
package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
)
func (app *Config) routes() http.Handler {
mux := chi.NewRouter()
// specify who is allowed to connect
mux.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"https://*", "http://*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
ExposedHeaders: []string{"Link"},
AllowCredentials: true,
MaxAge: 300,
}))
mux.Use(middleware.Heartbeat("/ping"))
mux.Post("/", app.Broker)
2024-08-28 19:40:50 +00:00
mux.Post("/handle", app.HandleSubmission)
2024-08-28 07:28:34 +00:00
return mux
}