// @bun
import{Y as _}from"../chunk-9p8h8aej.js";import{Db as G}from"../chunk-2vpsbhpm.js";import{join as C}from"path";import{jsx as L}from"react/jsx-runtime";function N(n,t){let l=Object.keys(t).sort((p,w)=>w.length-p.length).map((p)=>p.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),h=new RegExp(l.join("|"),"g");return n.replace(h,(p)=>t[p])}async function B(n,t,l=[]){let h=[...l.map((e)=>`${n}/views/${e}.tsx`),`${n}/views/RootLayout.tsx`],p=new Set;for(let e of h){let s=t.moduleGraph.getModulesByFile(e);if(s)p=p.union(s)}let w=[],$=[],d={};for(let e of p)if(e)for(let s of e.importedModules){if(s.file.includes("module.css"))d[s.file]=s.ssrTransformResult.map.sourcesContent.join("");if(s.file.includes(".css"))$.push(s.file)}for(let e of $){let s=await t.transformRequest(e+"?direct"),i=e.includes("module.css"),c="";if(i)c=N(d[e],s.default);w.push({isDev:!0,id:e,content:i?c:s.code})}return w.map((e,s)=>{return L("style",{type:"text/css","data-vite-dev-id":e.id,children:e.content},s)})}async function I(n=[]){return n.map((t,l)=>{return L("style",{id:t?.id,type:"text/css",children:t.content},l)})}function k(n){return n.replace(/\x1b\[[0-9;]*m/g,"").replace(/\[[0-9;]*m/g,"").replace(/\n\s*\n/g,`
`).split(`
`).map((t)=>t.trim()).filter((t)=>t.length>0).join(`
`).trim()}function F(n){return`
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0"
    />

    <title>Error</title>
    <style>
      body {
        font-family: Arial, sans-serif;
        padding: 20px;
      }
      h1 {
        color: red;
      }
    </style>
  </head>
  <body>
  <div id="overlay"></div>
    <script type="module" src="/refresh.js"></script>
    <script type="module" src="/@vite/client"></script>
    <script>
      ${k.toString()}
      const err = ${JSON.stringify(n,Object.getOwnPropertyNames(n),2)}

      window.addEventListener('load', () => {
        const container = document.getElementById('overlay')
        const ErrorOverlay = customElements.get('vite-error-overlay')
        if (ErrorOverlay) {
      const overlay = new ErrorOverlay({ ...err, message: cleanupTerminalText(err.message) });
          container.appendChild(overlay)
        }
      })
    </script>
  </body>
</html>
`}var E=process.cwd(),T=C(E,"app");async function H(){let n=process.cwd(),t=await(await import("vite")).createServer({root:n,logLevel:"error",server:{watch:{usePolling:!0,interval:100,ignored:["**/storage/**","**/node_modules/**","**/.**"]},hmr:{clientPort:5174}},appType:"custom",resolve:{alias:{"@/app":T}}});process.env.ROOT_DIR=E,process.env.APP_DIR=T;async function l(e){let{pathname:s,host:i,protocol:c}=new URL(e.url);if(s.startsWith("/render-error.js"))return new Response("window.render_error = true",{headers:{"Content-Type":"application/javascript"}});if(s.startsWith("/refresh.js"))return new Response(`
          import RefreshRuntime from "${c}//${i}/@react-refresh";
          RefreshRuntime.injectIntoGlobalHook(window);
          window.$RefreshReg$ = () => {};
          window.$RefreshSig$ = () => (type) => type;
          window.__vite_plugin_react_preamble_installed__ = true;
        `,{headers:{"Content-Type":"application/javascript"}});try{let f=await fetch(`http://localhost:5174${s}`);if(f.ok)return f}catch(f){console.log(f)}}async function h(){try{return(await t.ssrLoadModule(C(T,"bootstrap.ts"),{fixStacktrace:!0})).app}catch(e){t.ws.send({type:"error",err:{...e,message:""}}),console.error(e)}}async function p(e){let s=e.fetch.bind(e);return{maxRequestBodySize:10737418240,fetch:async(i,c)=>{if(c.upgrade(i,{data:{headers:i.headers}}))return;if(!i.headers.get("x-forwarded-for")){let o=c.requestIP(i);i.headers.set("x-forwarded-for",o.address)}let{pathname:f}=new URL(i.url),r=await l(i);if(r instanceof Response)return r;try{let o=await s(i);if(o instanceof Response)return o;else{let u={},g={},P=(a,v)=>`"${a}": () => import("${v}")`,y=[];for(let a of["404",...e.getFlatComponentTree.call(e)]){let v=`${process.env.APP_DIR}`,R=await t.ssrLoadModule(`${v}/views/${a}.tsx`,{fixStacktrace:!0});u[a]=R.default,g[a]=R?.OpenGraph,y.push(P(a,`${v}/views/${a}.tsx`))}let x=`{${y.join(",")}}`;return await o({getStyles:async(a)=>await B(T,t,a),bootstrapModules:["/refresh.js","/app/client.tsx","/@vite/client"],viewImportMap:u,ogMap:g,loaders:x,cssManifest:{}})}}catch(o){if(f.startsWith("/api"))return new Response(JSON.stringify({error:o.message}),{status:500,headers:{"Content-Type":"application/json"}});return new Response(F(o),{headers:{"Content-Type":"text/html"}})}},idleTimeout:Number(process.env.SERVER_IDLE_TIMEOUT??10),port:process.env.PORT||5173,websocket:e.websocket}}await t.listen(5174);let w=await h(),$=await p(w),d=Bun.serve($);return w.onPublish((e,s,i)=>{d.publish(e,s,i)}),console.log(`Server started on http://localhost:${process.env.PORT||5173}`),t.watcher.on("change",async(e)=>{let s=e.replace(E,"");if(s.startsWith("/logs"))return;if(s.startsWith("/prisma"))return;if(s.startsWith("/app/views")){console.log(`[vite] ${s} changed. \uD83C\uDF5C Hot reloading...`);return}console.log(`[vite] ${s} changed. Reloading...`);let i=t.moduleGraph.getModulesByFile(e)??[];for(let c of Array.from(i))try{t.moduleGraph.invalidateModule(c)}catch(f){}try{let c=await h(),f=await p(c);c.onPublish((r,o,u)=>{d.publish(r,o,u)}),d.reload(f),t.ws.send({type:"custom",event:"http-reload"}),t.ws.send({type:"update",updates:[]})}catch(c){console.log("Error on server reload"),console.log(t.ssrFixStacktrace(c))}}),d}import{join as j}from"path";function U(n){let t=n.toString(),l=new Bun.CryptoHasher("sha1");return l.update(t),l.digest("hex")}if(!globalThis.URLPattern)globalThis.URLPattern=_;import{exists as J}from"fs/promises";var z=process.env.GEMI_PROJECT_DIR??"",O=j(process.cwd(),z),M=j(O,"app"),S=j(O,"dist");async function V(){let{app:n}=await import(`${S}/server/bootstrap.mjs`),t=await import(`${S}/client/.vite/manifest.json`),l=await import(`${S}/server/.vite/manifest.json`);process.env.ROOT_DIR=O,process.env.APP_DIR=M,process.env.DIST_DIR=S;let h={},p={},w={},$=(r,o)=>`"${r}": () => import("${o}")`,d=[];for(let r of["404",...n.getFlatComponentTree.call(n)]){let o=l[`app/views/${r}.tsx`];if(!o?.file){console.log(`Server file not found for ${r}`),console.log(o);let P=Object.keys(l),y=`app/views/${r}.tsx`;console.log(`${y} not found in server manifest`),console.log(P)}let u=await import(`${process.env.DIST_DIR}/server/${o?.file}`);h[r]=u.default,p[r]=u.OpenGraph;let g=t[`app/views/${r}.tsx`];if(g?.css&&g?.css.length>0)w[r]=g?.css;if(g)d.push($(r,`/${g?.file}`))}let e=`{${d.join(",")}}`,i=await Bun.file(`${S}/client/${t["app/client.tsx"].css}`).text();async function c(r){let{pathname:o}=new URL(r.url),u=new _({pathname:"/*.:filetype(png|txt|js|css|jpg|svg|jpeg|avif|webp|ico|ttf)"}),g=o.startsWith("/.well-known"),P=u.test({pathname:o})||g,y=o.startsWith("/api");if(P&&!y){let a=new URL(r.url),v=r.url.replace(a.origin,"").split("?")[0],R=`${S}/client${v.replace("/assets/assets","/assets")}`;if(!await J(R)&&a.pathname.includes(".js"))return new Response(`if(caches){caches?.delete("${R}")}window.location.reload();export {}`,{headers:{"Content-Type":"application/javascript"}});try{let m=Bun.file(R),D=U(m.lastModified);return new Response(m.stream(),{headers:{"Content-Type":m.type,"Cache-Control":"public, max-age=31536000, must-revalidate","Content-Length":String(m.size),ETag:D}})}catch(m){return n.onException?.(m),new Response("Not found",{status:404})}}let x=n.fetch.bind(n);try{let a=await x(r);if(a instanceof Response)return a;else{let v=[];return v.push({content:i}),await a({getStyles:async(b)=>{if(!b)return I([]);for(let m of b){let D=t[`app/views/${m}.tsx`];for(let A of D?.css??[]){let W=Bun.file(`${process.env.DIST_DIR}/client/${A}`);v.push({id:A,content:await W.text()})}}return I(v)},bootstrapModules:[`/${t["app/client.tsx"].file}`],loaders:e,viewImportMap:h,ogMap:p,cssManifest:w})}}catch(a){if(console.error(a),o.startsWith("/api"))return new Response(JSON.stringify({error:a.message}),{status:500,headers:{"Content-Type":"application/json"}});return n.onException?.(a),new Response(a.stack,{status:500})}}let f=Bun.serve({maxRequestBodySize:10737418240,fetch:async(r,o)=>{if(!r.headers.get("x-forwarded-for")){let u=o.requestIP(r);r.headers.set("x-forwarded-for",u.address)}return await c(r)},idleTimeout:Number(process.env.SERVER_IDLE_TIMEOUT??10),port:process.env.PORT||5173});return console.log("Production server running on",f.url.href),f}export{V as startProdServer,H as startDevServer};

//# debugId=C2A81D6F3A16D82B64756E2164756E21
