refac: rethought the complete workflow and deployement flow ; docs etc.
This commit is contained in:
1 parent
4a6209a8db
commit
09bd5afa4a
26 files changed
+800
-334
No files matched your search
+23
-6
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/MadAppGang/httplog"
|
||||
"github.com/go-chi/chi/v5"
|
||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/go-chi/jwtauth/v5"
|
||||
)
|
||||
@@ -55,6 +56,7 @@ func InitBackendRoutes(container *UseCases) *chi.Mux {
|
||||
|
||||
enableLoggingIfDev(r, "backend")
|
||||
|
||||
r.Use(chimiddleware.GetHead)
|
||||
r.Use(middleware.JsonContentTypeMiddleware)
|
||||
r.Get("/", GetHelloWorld)
|
||||
r.Group(func(r chi.Router) {
|
||||
@@ -77,19 +79,34 @@ func InitFrontendRoutes() *chi.Mux {
|
||||
return r
|
||||
}
|
||||
|
||||
func InitRoutes(container *UseCases) *chi.Mux {
|
||||
backend := InitBackendRoutes(container)
|
||||
frontend := InitFrontendRoutes()
|
||||
func GetHealth(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
_, _ = w.Write([]byte("ok"))
|
||||
}
|
||||
|
||||
apiRouter := chi.NewRouter()
|
||||
apiRouter.Use(cors.Handler(cors.Options{
|
||||
AllowedOrigins: strings.Split(os.Getenv("CORS_ALLOWED_ORIGINS"), ";"),
|
||||
func enableCorsIfConfigured(r *chi.Mux) {
|
||||
origins := os.Getenv("CORS_ALLOWED_ORIGINS")
|
||||
if origins == "" {
|
||||
return
|
||||
}
|
||||
r.Use(cors.Handler(cors.Options{
|
||||
AllowedOrigins: strings.Split(origins, ";"),
|
||||
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
|
||||
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
|
||||
ExposedHeaders: []string{"Link"},
|
||||
AllowCredentials: false,
|
||||
MaxAge: 300,
|
||||
}))
|
||||
}
|
||||
|
||||
func InitRoutes(container *UseCases) *chi.Mux {
|
||||
backend := InitBackendRoutes(container)
|
||||
frontend := InitFrontendRoutes()
|
||||
|
||||
apiRouter := chi.NewRouter()
|
||||
enableCorsIfConfigured(apiRouter)
|
||||
apiRouter.Use(chimiddleware.GetHead)
|
||||
apiRouter.Get("/healthz", GetHealth)
|
||||
apiRouter.Mount("/v1", backend)
|
||||
apiRouter.Mount("/", frontend)
|
||||
|
||||
|
||||
Reference in new issue
Block a user