File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ var Module = fx.Module(
8080 }),
8181 fx .Provide (func (cfg Config ) handlers.Config {
8282 // Default and normalize API path/host
83- if cfg .HTTP .API .Path == "" {
83+ if cfg .HTTP .API .Host == "" {
8484 cfg .HTTP .API .Path = "/api"
8585 }
8686 // Ensure leading slash and trim trailing slash (except root)
Original file line number Diff line number Diff line change 11package handlers
22
33import (
4+ "fmt"
45 "path"
6+ "strings"
57
68 "github.com/android-sms-gateway/server/internal/sms-gateway/openapi"
79 "github.com/gofiber/fiber/v2"
@@ -15,6 +17,21 @@ type rootHandler struct {
1517}
1618
1719func (h * rootHandler ) Register (app * fiber.App ) {
20+ if h .config .PublicPath != "/api" {
21+ app .Use (func (c * fiber.Ctx ) error {
22+ err := c .Next ()
23+
24+ location := c .GetRespHeader (fiber .HeaderLocation )
25+ if after , ok := strings .CutPrefix (location , "/api" ); ok {
26+ c .Set (fiber .HeaderLocation , path .Join (h .config .PublicPath , after ))
27+ }
28+
29+ fmt .Printf ("Request: %s %s\n " , c .Method (), location )
30+
31+ return err
32+ })
33+ }
34+
1835 h .healthHandler .Register (app )
1936
2037 h .registerOpenAPI (app )
@@ -27,7 +44,7 @@ func (h *rootHandler) registerOpenAPI(router fiber.Router) {
2744
2845 router .Use (func (c * fiber.Ctx ) error {
2946 if c .Path () == "/api" || c .Path () == "/api/" {
30- return c .Redirect (path . Join ( h . config . PublicPath , " docs") , fiber .StatusMovedPermanently )
47+ return c .Redirect ("/api/ docs" , fiber .StatusMovedPermanently )
3148 }
3249
3350 return c .Next ()
You can’t perform that action at this time.
0 commit comments