From 16e611ff8b8c19e0f714f38d5b5546582fc4d069 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 28 Mar 2024 14:35:36 -0500 Subject: [PATCH] chore: ensure root handler has sudomain app mw Enterprise routes like scim touch this. --- coderd/coderd.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/coderd/coderd.go b/coderd/coderd.go index 1e4e2b05f60f5..77d52d05b54a6 100644 --- a/coderd/coderd.go +++ b/coderd/coderd.go @@ -648,6 +648,10 @@ func New(options *Options) *API { httpmw.CSRF(options.SecureAuthCookie), ) + // This incurs a performance hit from the middleware, but is required to make sure + // we do not override subdomain app routes. + r.Get("/latency-check", tracing.StatusWriterMiddleware(prometheusMW(LatencyCheck())).ServeHTTP) + r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) }) // Attach workspace apps routes. @@ -1192,15 +1196,7 @@ func New(options *Options) *API { // static files since it only affects browsers. r.NotFound(cspMW(compressHandler(httpmw.HSTS(api.SiteHandler, options.StrictTransportSecurityCfg))).ServeHTTP) - // This must be before all middleware to improve the response time. - // So make a new router, and mount the old one as the root. - rootRouter := chi.NewRouter() - // This is the only route we add before all the middleware. - // We want to time the latency of the request, so any middleware will - // interfere with that timing. - rootRouter.Get("/latency-check", tracing.StatusWriterMiddleware(prometheusMW(LatencyCheck())).ServeHTTP) - rootRouter.Mount("/", r) - api.RootHandler = rootRouter + api.RootHandler = r return api }