@@ -36,11 +36,12 @@ import (
3636 "github.com/ory/kratos/x"
3737 "github.com/ory/kratos/x/nosurfx"
3838 "github.com/ory/x/healthx"
39+ "github.com/ory/x/httprouterx"
3940 "github.com/ory/x/metricsx"
4041 "github.com/ory/x/networkx"
4142 "github.com/ory/x/otelx"
4243 "github.com/ory/x/otelx/semconv"
43- prometheus "github.com/ory/x/prometheusx"
44+ "github.com/ory/x/prometheusx"
4445 "github.com/ory/x/reqlog"
4546 "github.com/ory/x/urlx"
4647)
@@ -49,6 +50,8 @@ func init() {
4950 graceful .DefaultShutdownTimeout = 120 * time .Second
5051}
5152
53+ var prometheusManager = prometheusx .NewMetricsManagerWithPrefix ("kratos" , prometheusx .HTTPMetrics , config .Version , config .Commit , config .Date )
54+
5255func servePublic (ctx context.Context , r * driver.RegistryDefault , cmd * cobra.Command ) (func () error , error ) {
5356 cfg := r .Config ().ServePublic (ctx )
5457 l := r .Logger ()
@@ -67,9 +70,10 @@ func servePublic(ctx context.Context, r *driver.RegistryDefault, cmd *cobra.Comm
6770 n .UseFunc (semconv .Middleware )
6871 n .Use (publicLogger )
6972 n .Use (x .HTTPLoaderContextMiddleware (r ))
73+ n .UseFunc (httprouterx .NoCacheNegroni )
7074 n .Use (sqa (ctx , cmd , r ))
7175
72- router := x .NewRouterPublic (r )
76+ router := httprouterx .NewRouterPublic (prometheusManager )
7377 csrf := nosurfx .NewCSRFHandler (otelx .SpanNameRecorderMiddleware (router ), r )
7478
7579 // we need to always load the CORS middleware even if it is disabled, to allow hot-enabling CORS
@@ -90,7 +94,7 @@ func servePublic(ctx context.Context, r *driver.RegistryDefault, cmd *cobra.Comm
9094 csrf .DisablePath (healthx .AliveCheckPath )
9195 csrf .DisablePath (healthx .ReadyCheckPath )
9296 csrf .DisablePath (healthx .VersionPath )
93- csrf .DisablePath (prometheus .MetricsPrometheusPath )
97+ csrf .DisablePath (prometheusx .MetricsPrometheusPath )
9498
9599 r .RegisterPublicRoutes (ctx , router )
96100
@@ -154,15 +158,20 @@ func serveAdmin(ctx context.Context, r *driver.RegistryDefault, cmd *cobra.Comma
154158 adminLogger := reqlog .NewMiddlewareFromLogger (l , "admin#" + cfg .BaseURL .String ())
155159
156160 if cfg .RequestLog .DisableHealth {
157- adminLogger .ExcludePaths (x .AdminPrefix + healthx .AliveCheckPath , x .AdminPrefix + healthx .ReadyCheckPath , x .AdminPrefix + prometheus .MetricsPrometheusPath )
161+ adminLogger .ExcludePaths (
162+ httprouterx .AdminPrefix + healthx .AliveCheckPath ,
163+ httprouterx .AdminPrefix + healthx .ReadyCheckPath ,
164+ httprouterx .AdminPrefix + prometheusx .MetricsPrometheusPath ,
165+ )
158166 }
159167 n .UseFunc (semconv .Middleware )
160168 n .Use (adminLogger )
161- n .UseFunc (x .RedirectAdminMiddleware )
169+ n .UseFunc (httprouterx .AddAdminPrefixIfNotPresentNegroni )
170+ n .UseFunc (httprouterx .NoCacheNegroni )
162171 n .Use (x .HTTPLoaderContextMiddleware (r ))
163172 n .Use (sqa (ctx , cmd , r ))
164173
165- router := x . NewRouterAdmin ( r )
174+ router := httprouterx . NewRouterAdminWithPrefix ( prometheusManager )
166175 r .RegisterAdminRoutes (ctx , router )
167176
168177 n .UseHandler (router )
@@ -271,8 +280,8 @@ func sqa(ctx context.Context, cmd *cobra.Command, d driver.Registry) *metricsx.S
271280
272281 session .RouteWhoami ,
273282
274- x .AdminPrefix + "/" + schema .SchemasPath ,
275- x .AdminPrefix + identity .RouteCollection ,
283+ httprouterx .AdminPrefix + "/" + schema .SchemasPath ,
284+ httprouterx .AdminPrefix + identity .RouteCollection ,
276285
277286 settings .RouteInitBrowserFlow ,
278287 settings .RouteInitAPIFlow ,
@@ -292,7 +301,7 @@ func sqa(ctx context.Context, cmd *cobra.Command, d driver.Registry) *metricsx.S
292301 link .RouteAdminCreateRecoveryLink ,
293302
294303 errorx .RouteGet ,
295- prometheus .MetricsPrometheusPath ,
304+ prometheusx .MetricsPrometheusPath ,
296305 },
297306 BuildVersion : config .Version ,
298307 BuildHash : config .Commit ,
0 commit comments