import{serveStatic as L}from"hono/serve-static";import{withPathPrefix as e}from"@redocly/theme/core/utils";import{ServerRoutes as l,TELEMETRY_ENABLED as r}from"../../../constants/index.js";import{PUBLIC_STATIC_FOLDER as H}from"../../constants/common.js";import{authMiddleware as R}from"../middleware/authMiddleware.js";import{ensureSearchData as T}from"../middleware/ensureSearchData.js";import{dynamicMiddleware as c}from"../middleware/dynamic-middleware/dynamic-middleware.js";import{installRoutes as O}from"../../plugins/dev-onboarding/api/routes/index.js";import{authorizeHandler as g,oidcCallbackHandler as C,logoutHandler as p,idpLoginHandler as S,redoclyLoginCallbackHandler as P,samlCallbackHandler as D,redoclyTokenLoginHandler as I,inviteHandler as h}from"./auth.js";import{appDataHandler as w}from"./app-data.js";import{searchFacetsHandler as B,searchHandler as U}from"./search.js";import{dynamicRouteHandler as M}from"./dynamic-route.js";import{pageDataHandler as Y,sharedPageDataHandler as y}from"./page-data.js";import{pathPrefixRedirectHandler as G}from"./path-prefix-redirect.js";import{getRoutesByLineHandler as E,resolvePathHandler as s,resolvePathsHandler as N,resolveSlugHandler as f}from"./resolve-route.js";import{feedbackHandler as k}from"./feedback.js";import{loggerMiddleware as v}from"../middleware/loggerMiddleware.js";import{responseHeadersMiddleware as F}from"../middleware/responseHeadersMiddleware.js";import{idleTimeoutMiddleware as K}from"../middleware/idleTimeoutMiddleware.js";import{telemetryHandler as V}from"./telemetry.js";import{otelTracesHandler as b}from"./otel/otel.js";import{healthCheckHandler as x}from"./health.js";import{askAiHandler as z}from"./ask-ai.js";import{replayOauth2RedirectCallbackHandler as Z}from"./replay-oauth2-redirect.js";import{corsMiddleware as $}from"../middleware/corsMiddleware.js";import{installApiRoutes as j}from"./api-functions.js";import{cookieMiddleware as q}from"../middleware/cookieMiddleware.js";import{staticContentHandler as J}from"../routes/static-content.js";import{infoHandler as A}from"./info.js";function Da(a,i,m){const{resolveRouteData:t,readStaticAsset:o}=m;a.use("*",K()),a.use("*",q()),a.use("*",c(i)),a.use("*",R(i)),a.use("*",v()),a.use("*",F(i)),a.use("*",L({root:`./${H}`,getContent:(n,_)=>J(n,_,i,o)})),a.use(e(l.FEEDBACK),$({allowMethods:["POST"]})),a.use("*",Q(i));const d=T(i);a.use(e(l.INFO),A()),a.get(e(l.SHARED_PAGE_DATA),y(i)),a.get(e(l.PAGE_DATA),Y(i,t)),a.get(e(l.APP_DATA),w(i)),a.post(e(l.SEARCH),d,U(i)),a.post(e(l.SEARCH_FACETS),d,B(i)),a.post(e(l.AUTHORIZATION),g),a.post(e(l.LOGOUT),p(i)),a.get(e(l.LOGOUT),p(i)),a.get(e(l.OIDC_CALLBACK),C(i)),a.get(e(l.REDOCLY_TOKEN_LOGIN),I(i)),a.get(e(l.REDOCLY_LOGIN_CALLBACK),P()),a.get(e(l.IDP_LOGIN),S(i)),a.post(e(l.SAML_CALLBACK),D(i)),a.get(e(l.INVITE),h),a.get(e(l.HEALTH),x),O(a,i),j(a,i,t),a.post(e(l.FEEDBACK),k),a.post(e(l.RESOLVE_ROUTE_BY_PATH),s(i)),a.post(e(l.RESOLVE_ROUTES_BY_PATHS),N(i)),a.post(e(l.RESOLVE_ROUTE_BY_SLUG),f(i)),a.post(e(l.ASK_AI),z(i)),a.get(e(l.GET_ROUTES_BY_LINE),E(i)),r&&a.post(e(l.TELEMETRY),V),a.post(e(l.OTEL_TRACES),b),a.get(e(l.REPLAY_OAUTH2_CALLBACK),Z),a.all(e("/*"),M(i,t,o)),a.get("*",G),a.onError(n=>n instanceof Error&&"name"in n&&n.name==="URIError"?new Response("Malformed URL",{status:400}):new Response("Internal Server Error",{status:500}))}function Q(a){return async(i,m)=>{await a.waitForPluginsLifecycle(),await m()}}function Ia(a,i){a.get(e(l.INFO),A()),a.post(e(l.RESOLVE_ROUTE_BY_PATH),s(i)),a.post(e(l.RESOLVE_ROUTE_BY_SLUG),f(i)),a.get(e(l.GET_ROUTES_BY_LINE),E(i))}export{Ia as installDevRoutes,Da as installProdRoutes,Q as waitForPluginsLifecycle};
