@stacksjs/stx 0.2.229 → 0.2.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/{chunk-2n82qm71.js → chunk-18e804vq.js} +1 -1
  2. package/dist/{chunk-evnm04mk.js → chunk-39hy7f4g.js} +2 -2
  3. package/dist/{chunk-8mt7gk35.js → chunk-3h7exkbb.js} +1 -1
  4. package/dist/{chunk-z8v3qtzk.js → chunk-4j0fwfej.js} +1 -1
  5. package/dist/{chunk-k9gdaetd.js → chunk-4xzmg2xk.js} +1 -1
  6. package/dist/{chunk-yfj7tc37.js → chunk-58at6vf3.js} +1 -1
  7. package/dist/{chunk-edydd6c9.js → chunk-5n44cxqv.js} +1 -1
  8. package/dist/{chunk-x8w319bf.js → chunk-6k9e6vfx.js} +2 -2
  9. package/dist/{chunk-b318zf0z.js → chunk-7hdjf2d8.js} +1 -1
  10. package/dist/chunk-7qx5ebq7.js +3 -0
  11. package/dist/{chunk-tswv4p1r.js → chunk-7vj34efv.js} +1 -1
  12. package/dist/{chunk-yjzznatw.js → chunk-8hdb7abn.js} +1 -1
  13. package/dist/{chunk-v6015c7x.js → chunk-8tekg302.js} +1 -1
  14. package/dist/{chunk-k8kx4npc.js → chunk-8tth46zf.js} +1 -1
  15. package/dist/{chunk-17zts4jt.js → chunk-8ybja3e1.js} +1 -1
  16. package/dist/{chunk-yj90q1bk.js → chunk-ayv6vby2.js} +1 -1
  17. package/dist/{chunk-rhdr9jp2.js → chunk-b72rxkbf.js} +1 -1
  18. package/dist/{chunk-d4tnecbv.js → chunk-d729yxzx.js} +1 -1
  19. package/dist/{chunk-z61y1yv1.js → chunk-dn8x6vf7.js} +268 -268
  20. package/dist/{chunk-0wcpp78j.js → chunk-e63m9jhd.js} +2 -2
  21. package/dist/{chunk-9vnc4a3b.js → chunk-f0yhv8yr.js} +1 -1
  22. package/dist/{chunk-n3ba1kf9.js → chunk-fk4waw6p.js} +1 -1
  23. package/dist/{chunk-6ge7t20t.js → chunk-h2fq4ksg.js} +1 -1
  24. package/dist/{chunk-pnarrxms.js → chunk-h9z3rfk8.js} +1 -1
  25. package/dist/{chunk-g29rxrje.js → chunk-ht4wqwr6.js} +1 -1
  26. package/dist/{chunk-3nnja4z6.js → chunk-hwvzkhbe.js} +1 -1
  27. package/dist/{chunk-c6y91qmt.js → chunk-jewcmcaf.js} +1 -1
  28. package/dist/{chunk-qanmpzke.js → chunk-k4ejba6b.js} +1 -1
  29. package/dist/{chunk-0aj80aj9.js → chunk-kf2w2xxb.js} +1 -1
  30. package/dist/{chunk-8qhyzqk6.js → chunk-pq6rgbbw.js} +1 -1
  31. package/dist/{chunk-mkfeqges.js → chunk-pw21r03f.js} +1 -1
  32. package/dist/{chunk-4tqmx6dd.js → chunk-q9v240z7.js} +1 -1
  33. package/dist/{chunk-ctdrjf3m.js → chunk-r1ym4dxv.js} +1 -1
  34. package/dist/{chunk-nxf2s46y.js → chunk-sc3bz0z7.js} +1 -1
  35. package/dist/{chunk-5qhjeyp4.js → chunk-smr28g8g.js} +1 -1
  36. package/dist/{chunk-vy253t51.js → chunk-t13jx2p3.js} +1 -1
  37. package/dist/{chunk-s3sa0z97.js → chunk-t7had6e0.js} +1 -1
  38. package/dist/{chunk-ywpcqmrz.js → chunk-tgcbjer0.js} +1 -1
  39. package/dist/{chunk-bxb8v1ev.js → chunk-ty6pj7b5.js} +72 -72
  40. package/dist/{chunk-rgxtc72z.js → chunk-v4rgwxs1.js} +1 -1
  41. package/dist/{chunk-ypq3brzq.js → chunk-vmx4f37f.js} +1 -1
  42. package/dist/{chunk-53wyachb.js → chunk-x7v6xqz9.js} +1 -1
  43. package/dist/{chunk-07n6dv48.js → chunk-zs9j4xyx.js} +1 -1
  44. package/dist/cli.js +7 -7
  45. package/dist/craft-entry.js +1 -1
  46. package/dist/craft.js +1 -1
  47. package/dist/misc-directives.d.ts +8 -3
  48. package/dist/misc-directives.js +71 -2
  49. package/dist/page-action.d.ts +1 -1
  50. package/dist/page-action.js +4 -1
  51. package/dist/process.js +1 -1
  52. package/dist/production-server.js +1 -1
  53. package/dist/pwa.js +1 -1
  54. package/dist/signal-processing.js +1 -1
  55. package/dist/ssg.js +2 -2
  56. package/dist/ssr.js +15 -15
  57. package/dist/types/config-types.d.ts +17 -0
  58. package/dist/utils.js +9 -2
  59. package/package.json +5 -5
  60. package/dist/chunk-87m6cyay.js +0 -3
package/dist/ssr.js CHANGED
@@ -92,6 +92,14 @@ function parseCookies(cookieHeader) {
92
92
  function serializeCookie(name, value, options = {}) {
93
93
  return serializeSetCookie(name, value, options);
94
94
  }
95
+ function copyContextHeaders(from, into) {
96
+ for (const cookie of from.getSetCookie())
97
+ into.append("Set-Cookie", cookie);
98
+ from.forEach((value, key) => {
99
+ if (key.toLowerCase() !== "set-cookie")
100
+ into.set(key, value);
101
+ });
102
+ }
95
103
  function generateCsrfToken() {
96
104
  return crypto.randomBytes(32).toString("hex");
97
105
  }
@@ -146,9 +154,7 @@ export async function render(template, data = {}, options = {}) {
146
154
  "Content-Type": "text/html; charset=utf-8"
147
155
  });
148
156
  if (options.ctx)
149
- options.ctx.responseHeaders.forEach((value, key) => {
150
- headers.set(key, value);
151
- });
157
+ copyContextHeaders(options.ctx.responseHeaders, headers);
152
158
  return new Response(html, { headers });
153
159
  }
154
160
  export function createApp(config = {}) {
@@ -179,11 +185,11 @@ export function createApp(config = {}) {
179
185
  return null;
180
186
  }
181
187
  async function createContext(request, params) {
182
- const url = new URL(request.url), cookies = parseCookies(request.headers.get("Cookie")), responseHeaders = new Headers, cookiesToSet = [];
188
+ const url = new URL(request.url), cookies = parseCookies(request.headers.get("Cookie")), responseHeaders = new Headers;
183
189
  let sessionId = cookies[sessionCookieName];
184
190
  if (!sessionId) {
185
191
  sessionId = generateSessionId();
186
- cookiesToSet.push(serializeCookie(sessionCookieName, sessionId, {
192
+ responseHeaders.append("Set-Cookie", serializeCookie(sessionCookieName, sessionId, {
187
193
  httpOnly: !0,
188
194
  secure: url.protocol === "https:",
189
195
  sameSite: "Lax",
@@ -201,7 +207,8 @@ export function createApp(config = {}) {
201
207
  url.searchParams.forEach((value, key) => {
202
208
  query[key] = value;
203
209
  });
204
- const errors = session.flash("_errors") || {}, oldInput = session.flash("_old_input") || {}, ctx = {
210
+ const errors = session.flash("_errors") || {}, oldInput = session.flash("_old_input") || {};
211
+ return {
205
212
  request,
206
213
  url,
207
214
  params,
@@ -222,7 +229,7 @@ export function createApp(config = {}) {
222
229
  return await request.json();
223
230
  },
224
231
  setCookie(name, value, options = {}) {
225
- cookiesToSet.push(serializeCookie(name, value, options));
232
+ responseHeaders.append("Set-Cookie", serializeCookie(name, value, options));
226
233
  },
227
234
  flash(key, value) {
228
235
  session.flash(key, value);
@@ -240,11 +247,6 @@ export function createApp(config = {}) {
240
247
  return session.get("user");
241
248
  }
242
249
  };
243
- if (cookiesToSet.length > 0)
244
- cookiesToSet.forEach((cookie) => {
245
- responseHeaders.append("Set-Cookie", cookie);
246
- });
247
- return ctx;
248
250
  }
249
251
  const csrfMiddleware = async (ctx, next) => {
250
252
  if (["GET", "HEAD", "OPTIONS"].includes(ctx.request.method))
@@ -271,9 +273,7 @@ export function createApp(config = {}) {
271
273
  };
272
274
  try {
273
275
  const response = await next();
274
- ctx.responseHeaders.forEach((value, key) => {
275
- response.headers.set(key, value);
276
- });
276
+ copyContextHeaders(ctx.responseHeaders, response.headers);
277
277
  return response;
278
278
  } catch (error) {
279
279
  errorLogger.log(error instanceof Error ? error : Error(String(error)), { handler: "request" }, "error");
@@ -635,6 +635,23 @@ export interface StxConfig {
635
635
  * which is far harder to diagnose than a 404.
636
636
  */
637
637
  fallbackLayoutsDir?: string;
638
+ /**
639
+ * Where to look for a component `componentsDir` does not have.
640
+ *
641
+ * The component-side counterpart of `fallbackLayoutsDir`, and it exists for
642
+ * the same reason. A framework ships default components and lets an app
643
+ * override them by name: the app's directory is `componentsDir` and wins,
644
+ * anything it does not define falls back here.
645
+ *
646
+ * Without it, a host had one bad choice to make. Point `componentsDir` at
647
+ * the framework defaults and an app could never override a component - its
648
+ * own file was never even looked for. Point it at the app and every
649
+ * framework component stops resolving. Stacks' production server took the
650
+ * first option, so an app that had written its own `NativeAppShell.stx`
651
+ * still rendered the framework's, and the only symptom was that file's
652
+ * relative includes failing with ENOENT paths the author had never written.
653
+ */
654
+ fallbackComponentsDir?: string;
638
655
  /**
639
656
  * Path to the stores directory, resolved against `root`.
640
657
  *
package/dist/utils.js CHANGED
@@ -389,6 +389,7 @@ export async function userComponentFileExists(componentPath, componentsDir, pare
389
389
  if (Array.isArray(pluginDirs))
390
390
  for (const dir of pluginDirs)
391
391
  push(typeof dir === "string" ? dir : null);
392
+ push(options.fallbackComponentsDir);
392
393
  if (baseName.startsWith("./") || baseName.startsWith("../"))
393
394
  return fileExists(path.resolve(path.dirname(parentFilePath), `${baseName}.stx`));
394
395
  for (const dir of searchDirs) {
@@ -483,6 +484,8 @@ export async function renderComponentWithSlot(componentPath, props, slotContent,
483
484
  if (typeof dir === "string" && !searchDirs.includes(dir))
484
485
  searchDirs.push(dir);
485
486
  }
487
+ if (options.fallbackComponentsDir && !searchDirs.includes(options.fallbackComponentsDir))
488
+ searchDirs.push(options.fallbackComponentsDir);
486
489
  const normalizedSearchDirs = [...new Set(searchDirs.map((dir) => {
487
490
  if (!dir)
488
491
  return dir;
@@ -578,7 +581,8 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
578
581
  "__importedComponents",
579
582
  COMPONENT_CLIENT_FACTORIES_CONTEXT_KEY,
580
583
  "__stx_client_signal_names",
581
- "__stxServeContext"
584
+ "__stxServeContext",
585
+ "__stx_scope_seq"
582
586
  ]), filteredParentContext = {};
583
587
  for (const [key, val] of Object.entries(parentContext))
584
588
  if (!key.startsWith("__") || internalKeysToPreserve.has(key))
@@ -697,7 +701,10 @@ ${triedPaths.map((p) => ` - ${p}`).join(`
697
701
  preservedExpressions.add(match[1].trim());
698
702
  if (preservedExpressions.size > 0)
699
703
  parentContext.__stx_preserved_client_expressions = [...preservedExpressions];
700
- const scopeId = `stx_${baseName.replace(/[^a-zA-Z0-9]/g, "_")}_${++scopeIdCounter}_${Math.random().toString(36).slice(2, 8)}`;
704
+ const scopeSeq = parentContext.__stx_scope_seq ??= {
705
+ n: 0,
706
+ key: Bun.hash(String(parentContext.__filename ?? parentFilePath)).toString(36).slice(0, 6)
707
+ }, scopeId = `stx_${baseName.replace(/[^a-zA-Z0-9]/g, "_")}_${++scopeSeq.n}_${scopeSeq.key}`;
701
708
  let output = result;
702
709
  if (hasSignalScripts) {
703
710
  let propsJson = "";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.229",
4
+ "version": "0.2.231",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -117,12 +117,12 @@
117
117
  "dependencies": {
118
118
  "@cwcss/crosswind": "^0.2.14",
119
119
  "@stacksjs/clapp": "^0.2.0",
120
- "@stacksjs/desktop": "0.2.229",
121
- "@stacksjs/sanitizer": "0.2.229",
120
+ "@stacksjs/desktop": "0.2.231",
121
+ "@stacksjs/sanitizer": "0.2.231",
122
122
  "@stacksjs/ts-i18n": "^0.1.11",
123
- "bun-plugin-stx": "0.2.229",
123
+ "bun-plugin-stx": "0.2.231",
124
124
  "bunfig": "^0.15.17",
125
- "stx-router": "0.2.229",
125
+ "stx-router": "0.2.231",
126
126
  "ts-broadcasting": "^0.0.9",
127
127
  "ts-images": "^0.2.11",
128
128
  "ts-syntax-highlighter": "^0.2.1"
@@ -1,3 +0,0 @@
1
- // @bun
2
- import{Bg as b,Kg as JJ,yg as o,zg as e}from"./chunk-ywpcqmrz.js";import{Nm as m,Om as l,ap as g,fm as y,gm as P,lq as t,pm as v,wm as x}from"./chunk-z61y1yv1.js";import{Pt as a,qu as s,uu as OJ}from"./chunk-bqdbf8k2.js";import{Eu as R}from"./chunk-q891e1vj.js";import r from"fs";import B from"path";var{serve:IJ}=globalThis.Bun;function q(J,K,Q={}){let X=`${encodeURIComponent(J)}=${encodeURIComponent(K)}`;if(Q.maxAge!==void 0)X+=`; Max-Age=${Q.maxAge}`;if(Q.expires)X+=`; Expires=${Q.expires.toUTCString()}`;if(Q.path)X+=`; Path=${Q.path}`;if(Q.domain)X+=`; Domain=${Q.domain}`;if(Q.secure)X+="; Secure";if(Q.httpOnly)X+="; HttpOnly";if(Q.sameSite)X+=`; SameSite=${Q.sameSite}`;return X}async function KJ(J){let K=J.headers.get("content-type")||"",Q={},X=(Z,G)=>{let $=Q[Z];if($===void 0)Q[Z]=G;else if(Array.isArray($))$.push(G);else Q[Z]=[$,G]};if(K.includes("multipart/form-data")){let Z=await J.formData();for(let[G,$]of Z.entries())if(typeof $==="string")X(G,$);return Q}if(K.includes("application/x-www-form-urlencoded")){for(let[Z,G]of new URLSearchParams(await J.text()).entries())X(Z,G);return Q}return Q}function f(J){if(!J)return!1;let K=J.toUpperCase();return K!=="GET"&&K!=="HEAD"}async function h(J,K={}){let Q=K.request,X=K.method??Q?.method;if(!Q||!f(X))return{ran:!1};if(typeof J.action!=="function")return{ran:!1};let Z={};try{Z=await KJ(Q)}catch{}let G=await J.action({request:Q,form:Z,params:K.params??{},query:J.query??{},cookies:K.cookies??{}});if(G&&typeof G==="object"){let $=G,W=QJ($.cookies),I=$.redirect;if(typeof I==="string"&&I)return{redirect:I,ran:!0,...W.length>0?{cookies:W}:{}};let{cookies:_,redirect:w,...U}=$;if(Object.assign(J,U),W.length>0)return{ran:!0,cookies:W}}return{ran:!0}}function QJ(J){if(!J||typeof J!=="object"||Array.isArray(J))return[];let K=[];for(let[Q,X]of Object.entries(J)){if(!Q)continue;if(typeof X==="string"){K.push(q(Q,X));continue}if(X&&typeof X==="object"){let Z=X;if(typeof Z.value!=="string")continue;K.push(q(Q,Z.value,Z))}}return K}function u(J,K=[]){let Q=new Headers({Location:J,"Cache-Control":"no-store"});for(let X of K)Q.append("Set-Cookie",X);return new Response(null,{status:303,headers:Q})}async function HJ(J,K={}){return(await c(J,K)).html}async function d(J,K={}){let{html:Q,context:X,redirect:Z,cookies:G}=await c(J,K),$=m(X),W=l(X);if(Z)return{html:Q,redirect:Z,cookies:G,status:$,headers:W};let{extractStreamBoundaries:I}=await import("./chunk-qanmpzke.js"),_=I(X),w=J.streamTemplates;if(w&&Object.keys(w).length>0){let{processDirectives:U}=await import("./chunk-edydd6c9.js"),{defaultConfig:z}=await import("./chunk-ypq3brzq.js"),O=X.streamBoundaries||{},N={...z,autoShell:!1},L=Object.keys(w).map((V)=>({id:V,render:async()=>{let D=typeof O[V]==="function"?await O[V]():void 0;return U(w[V],{...X,$boundary:D},J.sourceFile,N,new Set)}})),E=new Set(L.map((V)=>V.id));_=[...(_||[]).filter((V)=>!E.has(V.id)),...L]}return{html:Q,boundaries:_&&_.length>0?_:void 0,cookies:G,status:$,headers:W}}async function c(J,K){let Q={__filename:J.sourceFile,__dirname:J.sourceFile.replace(/[/\\][^/\\]+$/,""),...K};if(!J.hasServerScripts&&!P(J.html))return{html:J.html,context:Q};for(let G of J.serverScriptContent)try{await g(G,Q,J.sourceFile)}catch($){console.warn(`[stx] Server script error in ${J.sourceFile}:`,$)}let X=await h(Q,{request:K.request,method:K.method,params:K.params??{},cookies:K.cookies??{}});if(X.redirect)return{html:J.html,context:Q,redirect:X.redirect,cookies:X.cookies};if(!P(J.html))return{html:J.html,context:Q,cookies:X.cookies};let Z=new Map;for(let[G,$]of Object.entries(J.placeholders))if($.expression)try{let W=x($.expression,Q);if($.type==="raw")Z.set(G,W!==void 0&&W!==null?String(W):"");else Z.set(G,W!==void 0&&W!==null?v(String(W)):"")}catch{Z.set(G,"")}return{html:y(J.html,Z),context:Q,cookies:X.cookies}}async function SJ(J,K={}){if(!J.hasServerScripts&&!P(J.fragment))return J.fragment;let Q={__filename:J.sourceFile,__dirname:J.sourceFile.replace(/[/\\][^/\\]+$/,""),...K};for(let Z of J.serverScriptContent)try{await g(Z,Q,J.sourceFile)}catch(G){console.warn(`[stx] Server script error in ${J.sourceFile}:`,G)}if(!P(J.fragment))return J.fragment;let X=new Map;for(let[Z,G]of Object.entries(J.placeholders))if(G.expression)try{let $=x(G.expression,Q);if(G.type==="raw")X.set(Z,$!==void 0&&$!==null?String($):"");else X.set(Z,$!==void 0&&$!==null?v(String($)):"")}catch{X.set(Z,"")}return y(J.fragment,X)}OJ();import C from"zlib";import{promisify as n}from"util";var XJ=n(C.brotliCompress),ZJ=n(C.gzip),$J=["text/","application/json","application/javascript","application/xml","application/xhtml+xml","application/rss+xml","application/atom+xml","application/manifest+json","image/svg+xml"],GJ=["text/event-stream","multipart/x-mixed-replace"],UJ=1024;function WJ(J){if(!J)return!1;let K=J.toLowerCase();if(GJ.some((Q)=>K.startsWith(Q)))return!1;return $J.some((Q)=>K.startsWith(Q))}function YJ(J){let K=new Map;for(let Q of J.split(",")){let[X,...Z]=Q.trim().split(";"),G=X.trim().toLowerCase();if(!G)continue;let $=1;for(let W of Z){let I=/^\s*q\s*=\s*([\d.]+)\s*$/i.exec(W);if(!I)continue;let _=Number.parseFloat(I[1]);if(Number.isFinite(_))$=_}K.set(G,$)}return K}function jJ(J){if(!J)return null;let K=YJ(J),Q=K.get("*"),X=(Z)=>K.get(Z)??Q??0;if(X("br")>0)return"br";if(X("gzip")>0)return"gzip";return null}async function i(J,K,Q={}){if(K.headers.get("content-encoding"))return K;if(K.status===204||K.status===304||!K.body)return K;if(!WJ(K.headers.get("content-type")))return K;let X=jJ(J.headers.get("accept-encoding"));if(!X)return K;let Z;try{Z=new Uint8Array(await K.arrayBuffer())}catch{return K}let G=()=>new Response(Z,{status:K.status,statusText:K.statusText,headers:p(K.headers)});if(Z.length<(Q.threshold??UJ))return G();try{let $=X==="br"?await XJ(Z,{params:{[C.constants.BROTLI_PARAM_QUALITY]:Q.quality??5,[C.constants.BROTLI_PARAM_SIZE_HINT]:Z.length}}):await ZJ(Z);if($.length>=Z.length)return G();let W=p(K.headers);return W.set("Content-Encoding",X),W.set("Content-Length",String($.length)),new Response($,{status:K.status,statusText:K.statusText,headers:W})}catch{return G()}}function p(J){let K=new Headers(J),Q=K.get("Vary");if(!Q)return K.set("Vary","Accept-Encoding"),K;if(!Q.split(",").some((Z)=>Z.trim().toLowerCase()==="accept-encoding"))K.set("Vary",`${Q}, Accept-Encoding`);return K}var _J={".js":"application/javascript",".mjs":"application/javascript",".css":"text/css",".json":"application/json",".html":"text/html",".txt":"text/plain",".xml":"application/xml",".pdf":"application/pdf",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".avif":"image/avif",".svg":"image/svg+xml",".ico":"image/x-icon",".bmp":"image/bmp",".mp4":"video/mp4",".webm":"video/webm",".ogg":"audio/ogg",".mp3":"audio/mpeg",".wav":"audio/wav",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".eot":"application/vnd.ms-fontobject"};async function uJ(J={}){let K=B.resolve(J.outputDir||".output"),Q=J.port||3000,X=JJ(K);if(!X)console.error("[stx] No build manifest found. Run `stx build` first."),process.exit(1);console.log(`[stx] Production server loading ${X.routes.length} routes...`);let Z=new Map,G=new Map,$=new Map,W=new Map;for(let U of X.routes)try{let z=B.join(K,U.compiledPath),O=JSON.parse(await Bun.file(z).text());Z.set(U.pattern,O),$.set(U.pattern,s(O.html)),W.set(U.pattern,t(O.html));let N=B.join(K,U.fragmentPath);if(await Bun.file(N).exists())G.set(U.pattern,await Bun.file(N).text())}catch(z){console.warn(`[stx] Failed to load route ${U.pattern}:`,z)}let I=new Map,_=[];for(let U of X.routes)if(U.hasParams){let{regex:z,params:O}=a(U.pattern);_.push({regex:z,route:U,paramNames:O})}else I.set(U.pattern,U);let w=IJ({port:Q,async fetch(U){return i(U,await(async()=>{let O=new URL(U.url).pathname;if(J.onRequest){let Y=await J.onRequest(U);if(Y)return Y}if(J.apiRoutes?.[O])return J.apiRoutes[O](U);if((U.method==="GET"||U.method==="HEAD")&&O!=="/"){let Y=B.resolve(K,"public"),j;try{j=decodeURIComponent(O)}catch{j=O}if(!j.includes("\x00")){let F=B.resolve(Y,`.${j}`);if(F===Y||F.startsWith(`${Y}${B.sep}`))try{if(r.existsSync(F)&&r.statSync(F).isFile()){let S=B.extname(F).toLowerCase(),A=_J[S]||"application/octet-stream",M=O.startsWith("/__stx/")||/\.[0-9a-f]{8}\./.test(O);return new Response(Bun.file(F),{headers:{"Content-Type":A,"Cache-Control":M?"public, max-age=31536000, immutable":"public, max-age=3600"}})}}catch{}}}let N=e(U),L=null,E={};if(L=I.get(O)||null,!L)for(let{regex:Y,route:j,paramNames:F}of _){let H=O.match(Y);if(H){L=j,F.forEach((S,A)=>{E[S]=H[A+1]});break}}if(!L){let Y=I.get("/404")||null;if(Y){let j=Z.get(Y.pattern);if(j)return new Response(j.html,{status:404,headers:{"Content-Type":"text/html"}})}return new Response("Not Found",{status:404})}if(N){let Y=G.get(L.pattern);if(Y){let j=$.get(L.pattern);return new Response(Y,{headers:{"Content-Type":"text/html","X-STX-Fragment":"true",...W.has(L.pattern)?{"X-STX-Runtime":W.get(L.pattern)?"true":"false"}:{},...j?{"X-STX-Layout":j.layout,"X-STX-Layout-Group":j.group}:{},...b(),"Cache-Control":o}})}}let V=f(U.method),D=Z.get(L.pattern);if(!D){let Y=I.get("/500")||null;if(Y){let j=Z.get(Y.pattern);if(j)return new Response(j.html,{status:500,headers:{"Content-Type":"text/html"}})}return new Response("Internal Server Error",{status:500})}if(!V&&!D.hasServerScripts&&Object.keys(D.placeholders).length===0)return new Response(D.html,{status:D.status??200,headers:{"Content-Type":"text/html",...b(),"Cache-Control":"public, max-age=60"}});try{let{html:Y,boundaries:j,redirect:F,cookies:H,status:S,headers:A}=await d(D,{params:E,request:U,method:U.method});if(F)return u(F,H);if(j&&j.length>0){let{renderStreamingPage:T,streamToResponse:k}=await import("./chunk-qanmpzke.js");return k(T(Y,j,{timeoutMs:30000}),{status:S??D.status??200,headers:{"Cache-Control":"no-cache",...A}})}let M=new Headers({"Content-Type":"text/html",...b(),"Cache-Control":"no-cache"});for(let T of H??[])M.append("Set-Cookie",T);for(let[T,k]of Object.entries(A??{}))M.set(T,k);return new Response(Y,{status:S??D.status??200,headers:M})}catch(Y){return console.error(`[stx] Hydration error for ${O}:`,Y),new Response(D.html,{headers:{"Content-Type":"text/html"}})}})())}});return console.log(`[stx] Production server running at http://localhost:${Q}`),console.log(`[stx] Serving ${X.routes.length} routes (${Z.size} pre-loaded)`),{port:Q,stop:()=>w.stop()}}
3
- export{WJ as jg,jJ as kg,i as lg,q as mg,KJ as ng,f as og,h as pg,u as qg,HJ as rg,d as sg,SJ as tg,uJ as ug};