Commit: Bulk unfinished work

This commit is contained in:
2026-01-22 17:39:04 +01:00
parent 6c46b4efcc
commit 3a9acc42a2
68 changed files with 5047 additions and 1064 deletions

56
fx/routes.go Normal file
View File

@@ -0,0 +1,56 @@
package fx
import (
"log/slog"
"net/http"
"os"
connectcors "connectrpc.com/cors"
"github.com/rs/cors"
)
type Handler interface {
Handler() http.Handler
Path() string
}
type route struct {
path string
handler http.Handler
}
func NewRoute(path string, handler http.Handler) Handler {
return &route{
path: path,
handler: handler,
}
}
func (r *route) Handler() http.Handler {
return r.handler
}
func (r *route) Path() string {
return r.path
}
// NewServeMux builds a ServeMux that will route requests
// to the given EchoHandler.
func NewServeMux(handlers []Handler, logger *slog.Logger) http.Handler {
mux := http.NewServeMux()
for _, h := range handlers {
logger.Debug("Registering route", "path", h.Path())
mux.Handle(h.Path(), h.Handler())
}
handler := cors.New(cors.Options{
AllowedOrigins: []string{"http://10.8.0.3:3001", "http://10.8.0.3:3001/", os.Getenv("FRONTEND_URI")}, // replace with your domain
AllowedMethods: connectcors.AllowedMethods(),
AllowedHeaders: append(connectcors.AllowedHeaders(), "authentication", "Authentication"),
ExposedHeaders: connectcors.ExposedHeaders(),
AllowCredentials: true,
}).Handler(mux)
return handler
}