|
5 | 5 | "context" |
6 | 6 | "encoding/json" |
7 | 7 | "log/slog" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/cruxstack/github-ops-app/internal/github" |
10 | 11 | ) |
@@ -82,17 +83,27 @@ func (a *App) handleScheduledRequest(ctx context.Context, req Request) Response |
82 | 83 | } |
83 | 84 |
|
84 | 85 | // handleHTTPRequest routes HTTP requests based on path. |
| 86 | +// strips BasePath prefix if configured (e.g., "/api/v1" -> "/"). |
85 | 87 | func (a *App) handleHTTPRequest(ctx context.Context, req Request) Response { |
86 | | - switch req.Path { |
| 88 | + path := req.Path |
| 89 | + if a.Config.BasePath != "" { |
| 90 | + path = strings.TrimPrefix(path, a.Config.BasePath) |
| 91 | + if path == "" { |
| 92 | + path = "/" |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + switch path { |
87 | 97 | case "/server/status": |
88 | 98 | return a.handleStatusRequest(req) |
89 | 99 | case "/server/config": |
90 | 100 | return a.handleConfigRequest(req) |
91 | 101 | case "/webhooks", "/": |
92 | 102 | return a.handleWebhookRequest(ctx, req) |
93 | | - case "/scheduled/okta-sync": |
94 | | - return a.handleScheduledHTTPRequest(ctx, req) |
95 | 103 | default: |
| 104 | + if strings.HasPrefix(path, "/scheduled/") { |
| 105 | + return a.handleScheduledHTTPRequest(ctx, req, path) |
| 106 | + } |
96 | 107 | return errorResponse(404, "not found") |
97 | 108 | } |
98 | 109 | } |
@@ -147,15 +158,16 @@ func (a *App) handleWebhookRequest(ctx context.Context, req Request) Response { |
147 | 158 | } |
148 | 159 |
|
149 | 160 | // handleScheduledHTTPRequest processes scheduled events via HTTP POST. |
150 | | -func (a *App) handleScheduledHTTPRequest(ctx context.Context, req Request) Response { |
| 161 | +// path is the normalized path with BasePath already stripped. |
| 162 | +func (a *App) handleScheduledHTTPRequest(ctx context.Context, req Request, path string) Response { |
151 | 163 | if req.Method != "POST" { |
152 | 164 | return errorResponse(405, "method not allowed") |
153 | 165 | } |
154 | 166 |
|
155 | 167 | // extract action from path (e.g., "/scheduled/okta-sync" -> "okta-sync") |
156 | | - action := "okta-sync" |
157 | | - if len(req.Path) > len("/scheduled/") { |
158 | | - action = req.Path[len("/scheduled/"):] |
| 168 | + action := strings.TrimPrefix(path, "/scheduled/") |
| 169 | + if action == "" { |
| 170 | + return errorResponse(400, "missing scheduled action") |
159 | 171 | } |
160 | 172 |
|
161 | 173 | scheduledReq := Request{ |
|
0 commit comments