import{resolve as n,dirname as c}from"node:path";import{fileURLToPath as f}from"node:url";import{readFile as u}from"fs/promises";import{createReadStream as l}from"fs";import{telemetry as d}from"./telemetry/index.js";import{createRouter as v}from"./web-server/router.js";import{installProdRoutes as S}from"./web-server/routes/index.js";import{Store as E}from"./store.js";import{loadEnvVariables as P}from"./utils/envs/load-env-variables.js";import{startHttpServer as g}from"./web-server/http.js";import{readStaticData as A}from"./utils/static-data.js";import{startIdleTimeout as D}from"./web-server/middleware/idleTimeoutMiddleware.js";import{reporter as N}from"./tools/notifiers/reporter.js";import{EntitlementsProvider as R}from"./entitlements/entitlements-provider.js";import{DatabasePreconnectService as w}from"./providers/database/database-preconnect-service.js";import{isBuildMode as T}from"./utils/envs/is-build-mode.js";import{renderPage as H}from"./ssr/index.js";if(!T()){let p=function(){const r=process.argv.findIndex(o=>o==="--port"||o==="-p");if(r===-1)return null;const t=process.argv[r+1];if(t.startsWith("-"))return null;const i=parseInt(t,10);return isNaN(i)?null:i};const e=c(f(import.meta.url));P(e);const a=JSON.parse(await u(n(e,"./store.json"),"utf-8")),s=E.fromJson(a,{outdir:n(e,"../client"),serverOutDir:e,serverMode:!0,contentDir:""});await R.instance().init({ignoreTokenExpiration:!0}),process.env.NEW_CATALOG_ENABLED==="true"&&await w.init(e),m(s).catch(r=>{console.error(r)});async function m(r){d.initialize();const t=await v();S(t,r,{readStaticAsset:async o=>l(o),resolveRouteData:async o=>A(o.slug,r.outdir)}),N.printErrors();const i=p();return await g(t,i??process.env.PORT??4e3),D(),t}}export{H as renderPage};
