Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Route /pontusx requests to /sapphire (TEMP HACK) #635

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ func NewService(cfg *config.ServerConfig) (*Service, error) {
}, nil
}

// HACK HACK HACK
// Temporarily in place for frontend to test the PontusX endpoints.
// Remove once pontusx support is properly implemented.
func rewritePontusxToSapphireMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if strings.HasPrefix(r.URL.Path, "/v1/pontusx/") {
r.URL.Path = strings.Replace(r.URL.Path, "/v1/pontusx/", "/v1/sapphire/", 1)
r.RequestURI = ""
}
// Call the next handler in the chain.
next.ServeHTTP(w, r)
})
}

// Start starts the API service.
func (s *Service) Start() {
defer s.cleanup()
Expand Down Expand Up @@ -171,6 +185,7 @@ func (s *Service) Start() {
// Manually apply the metrics middleware; we want it to run always, and at the outermost layer.
// HandlerWithOptions() above does not apply it to some requests (404 URLs, requests with bad params, etc.).
handler = api.MetricsMiddleware(metrics.NewDefaultRequestMetrics(moduleName), *s.logger)(handler)
handler = rewritePontusxToSapphireMiddleware(handler)

server := &http.Server{
Addr: s.address,
Expand Down
Loading