import{otelTelemetry as s}from"./telemetry/telemetry.js";s.init();import{resolve as i,dirname as a}from"node:path";import{fileURLToPath as m}from"node:url";import{readFile as p}from"fs/promises";import{createReadStream as c}from"fs";import{createRouter as f}from"./web-server/router.js";import{installProdRoutes as l}from"./web-server/routes/index.js";import{Store as u}from"./store.js";import{telemetry as d}from"../cli/telemetry/index.js";import{loadEnvironmentVariables as v}from"../shared/env.js";import{startHttpServer as R}from"./web-server/http.js";import{readStaticData as S}from"./utils/static-data.js";import{startIdleTimeout as O}from"./web-server/middleware/idleTimeoutMiddleware.js";import{reporter as y}from"./utils/index.js";import{EntitlementsProvider as E}from"./entitlements/entitlements-provider.js";const n=a(m(import.meta.url));v(n),d.updateContext({version:process.env.REDOCLY_PORTAL_VERSION,anonymousId:"ANONYMOUS",platform:process.platform});const N=JSON.parse(await p(i(n,"./store.json"),"utf-8")),P=u.fromJson(N,{outdir:i(n,"../client"),serverOutDir:n,serverMode:!0,contentDir:""});await E.instance().init({ignoreTokenExpiration:!0}),T(P).catch(r=>{console.error(r)});async function T(r){const t=await f();l(t,r,{readStaticAsset:async o=>c(o),resolveRouteData:async o=>S(o.slug,r.outdir)}),y.printErrors();const e=g();return await R(t,e??process.env.PORT??4e3),O(),t}function g(){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 e=parseInt(t,10);return isNaN(e)?null:e}
