import{withPathPrefix as I}from"@redocly/theme/core/utils";import{SSR_RENDER_MODE as O}from"../constants/common.js";import{canAccessResource as P,filterDataByAccessDeep as l}from"../utils/rbac.js";import{logger as h,readSharedData as v}from"../utils/index.js";import{workers as R}from"../workers/worker-pool.js";import{render as L}from"./render.js";import{getServerProps as x}from"./server-side-props/get-server-props.js";async function U(e,o,a,r){const i=h.startTiming(),t=r.routesSharedData.get(e.slug)||{},{isAuthenticated:m,teams:d,claims:{name:D,picture:w,email:g}}=a?.get("auth")||{claims:{}},s={isAuthenticated:m,email:g,teams:d},b=Object.fromEntries(await Promise.all(Object.entries(t).map(async([C,u])=>[u,await v(u,r.outdir)]))),E=l(b,s,r.config.rbac,r.config.requiresLogin),q=l(r.globalData,s,r.config.rbac,r.config.requiresLogin),p=P(e,s,r.config.rbac,r.config.requiresLogin),S=!!r.compilationErrors?.length?{templateId:"compilation-error",props:{compilationErrors:r.compilationErrors},sharedDataIds:{}}:null,f={page:{templateId:e.templateId,slug:I(e.slug),versions:l(e.versions,s,r.config.rbac,r.config.requiresLogin),props:o,sharedDataIds:p?t:{},request:{search:a?.req.raw.context.url?.search||"",url:a?.req.raw.context.url?.href||""},userInfo:{isAuthenticated:m,name:D,picture:w,email:g,teams:d},...S},store:{globalData:q,cliOptions:r.cliOptions,config:r.config,ssr:r.ssr,hasSitemap:r.hasSitemap},sharedData:p?E:{},serverOutDir:r.serverOutDir,outdir:r.outdir,ssrHref:y(a)};let n,c;return O==="worker"?{html:n,statusCode:c}=await R.exec("render",[f]):{html:n,statusCode:c}=await L(f),h.verboseTime(i,`Page rendered ${e.slug}`),{html:n,props:o,statusCode:c}}function y(e){const o=e?.req.raw.url;if(!o)return"";const a=new URL(o),r=e?.req.raw.headers,i=r?.get("x-forwarded-proto")||a.protocol.replace(":",""),t=r?.get("x-forwarded-host")||a.host;return`${i}://${t}`}export{x as getServerProps,U as renderPage};
