@vesk/vesk-cli 0.2.90 → 0.2.91

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 (2) hide show
  1. package/dist/cli.js +53 -2
  2. package/package.json +5 -5
package/dist/cli.js CHANGED
@@ -37533,6 +37533,19 @@ export async function handleRequest(request) {
37533
37533
  const pathname = url.pathname;
37534
37534
  const isDataRequest = request.headers.get('x-vesk-data') === '1';
37535
37535
  ${serverStoreLine}
37536
+ // During SSR, fetch() with a relative URL (e.g. '/api/student') throws
37537
+ // because undici requires an absolute URL and there is no browser
37538
+ // origin to resolve against. Wrap globalThis.fetch for the duration
37539
+ // of the handler so relative API calls resolve against the request's
37540
+ // origin \u2014 matching what the client does automatically.
37541
+ const origin = url.origin;
37542
+ const origFetch = globalThis.fetch;
37543
+ globalThis.fetch = async (input, init) => {
37544
+ if (typeof input === 'string' && input.startsWith('/')) {
37545
+ input = origin + input;
37546
+ }
37547
+ return origFetch(input, init);
37548
+ };
37536
37549
 
37537
37550
  if (__prerendered.has(pathname) && !isDataRequest) {
37538
37551
  return new Response(null, { status: 308, headers: { Location: '/_vesk/static/public' + (pathname.endsWith('/') ? pathname + 'index.html' : pathname + '.html') } });
@@ -37627,6 +37640,7 @@ ${eventsRequestLine}
37627
37640
  headers: { 'Content-Type': 'text/html' },
37628
37641
  });
37629
37642
  } catch (e) {
37643
+ globalThis.fetch = origFetch;
37630
37644
  // Any error that escapes the route (a thrown exception, a bad import, a
37631
37645
  // middleware failure, ...) must not bubble out of handleRequest. On
37632
37646
  // serverless platforms (Vercel, Netlify, Cloudflare) an uncaught throw is
@@ -51015,7 +51029,16 @@ function extractMiddlewareParts(src2) {
51015
51029
  }
51016
51030
  const params = target.params.length ? src2.slice(target.params[0].start, target.params[target.params.length - 1].end) : "";
51017
51031
  const body = src2.slice(target.body.start + 1, target.body.end - 1);
51018
- return { params, body: body.trim() };
51032
+ const decls = [];
51033
+ for (const stmt of ast.body) {
51034
+ if (stmt.type === "VariableDeclaration") {
51035
+ decls.push(src2.slice(stmt.start, stmt.end).trim());
51036
+ } else if (stmt.type === "ExportNamedDeclaration" && stmt.declaration?.type === "VariableDeclaration") {
51037
+ decls.push(src2.slice(stmt.declaration.start, stmt.declaration.end).trim());
51038
+ }
51039
+ }
51040
+ const bodyWithDecls = decls.length > 0 ? decls.join("\n") + "\n" + body.trim() : body.trim();
51041
+ return { params, body: bodyWithDecls };
51019
51042
  } catch {
51020
51043
  return fallbackExtractMiddleware(src2);
51021
51044
  }
@@ -53973,8 +53996,16 @@ async function startProdServer(outDir, options) {
53973
53996
  if (params) {
53974
53997
  const mod = await loadFunction(route.function);
53975
53998
  if (mod) {
53999
+ const webRequest = makeWebRequest(req, url.href, maxBodyBytes);
54000
+ const origin = new URL(url.href).origin;
54001
+ const origFetch = globalThis.fetch;
54002
+ globalThis.fetch = async (input, init) => {
54003
+ if (typeof input === "string" && input.startsWith("/")) {
54004
+ input = origin + input;
54005
+ }
54006
+ return origFetch(input, init);
54007
+ };
53976
54008
  try {
53977
- const webRequest = makeWebRequest(req, url.href, maxBodyBytes);
53978
54009
  let cachedResult = null;
53979
54010
  if (route.revalidate && route.revalidate > 0) {
53980
54011
  const { pageIsr: pageIsr2 } = await Promise.resolve().then(() => (init_index_server(), index_server_exports));
@@ -54045,6 +54076,8 @@ async function startProdServer(outDir, options) {
54045
54076
  res.writeHead(500, { "Content-Type": "text/html" });
54046
54077
  res.end(errorHtml || renderDefaultErrorPage({ message: process.env.NODE_ENV !== "production" ? err.message : void 0, url: url.pathname, headExtra: bakedHeadExtra }));
54047
54078
  return;
54079
+ } finally {
54080
+ globalThis.fetch = origFetch;
54048
54081
  }
54049
54082
  }
54050
54083
  }
@@ -67635,6 +67668,14 @@ Object.defineProperty(__components, ${JSON.stringify(cname)}, { get: () => __com
67635
67668
  async function renderSSR() {
67636
67669
  const ssg2 = globalThis;
67637
67670
  ssg2.__vsk_ssr_data = {};
67671
+ const origin = url.origin;
67672
+ const origFetch = globalThis.fetch;
67673
+ globalThis.fetch = async (input, init) => {
67674
+ if (typeof input === "string" && input.startsWith("/")) {
67675
+ input = origin + input;
67676
+ }
67677
+ return origFetch(input, init);
67678
+ };
67638
67679
  let freshToken;
67639
67680
  try {
67640
67681
  return await withSsrStore2(async () => {
@@ -67714,6 +67755,7 @@ ${prettifyHtml(body)}
67714
67755
  });
67715
67756
  } finally {
67716
67757
  const token = freshToken;
67758
+ globalThis.fetch = origFetch;
67717
67759
  dropSsrSlot2(token);
67718
67760
  delete ssg2[`__vsk_ssr_data_${token}`];
67719
67761
  delete ssg2[`__vsk_ssr_promises_${token}`];
@@ -67724,6 +67766,14 @@ ${prettifyHtml(body)}
67724
67766
  function renderSSRStream() {
67725
67767
  const sst = globalThis;
67726
67768
  sst.__vsk_ssr_data = {};
67769
+ const origin = url.origin;
67770
+ const origFetchStream = globalThis.fetch;
67771
+ globalThis.fetch = async (input, init) => {
67772
+ if (typeof input === "string" && input.startsWith("/")) {
67773
+ input = origin + input;
67774
+ }
67775
+ return origFetchStream(input, init);
67776
+ };
67727
67777
  async function* raw2() {
67728
67778
  const chain = cleanChain;
67729
67779
  const hasLayout = chain.some((n) => n.layout && existsSync43(resolve39(appDirPath, n.sourceDir, "layout.vsk")));
@@ -67796,6 +67846,7 @@ ${prettifyHtml(body)}
67796
67846
  } while (!result.done);
67797
67847
  } finally {
67798
67848
  const token = streamStore.token;
67849
+ globalThis.fetch = origFetchStream;
67799
67850
  dropSsrSlot2(token);
67800
67851
  if (token) {
67801
67852
  delete sst[`__vsk_ssr_data_${token}`];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/vesk-cli",
3
- "version": "0.2.90",
3
+ "version": "0.2.91",
4
4
  "type": "module",
5
5
  "description": "Vesk — compiler-first framework for the post-VDOM web. vesk dev, vesk build.",
6
6
  "bin": {
@@ -8,10 +8,10 @@
8
8
  },
9
9
  "main": "./dist/cli.js",
10
10
  "dependencies": {
11
- "@vesk/adapter": "^0.2.90",
12
- "@vesk/compiler": "^0.2.90",
13
- "@vesk/plugin-tailwind": "^0.2.90",
14
- "@vesk/runtime": "^0.2.90",
11
+ "@vesk/adapter": "^0.2.91",
12
+ "@vesk/compiler": "^0.2.91",
13
+ "@vesk/plugin-tailwind": "^0.2.91",
14
+ "@vesk/runtime": "^0.2.91",
15
15
  "esrap": "^2.3.0",
16
16
  "typescript": "^5.8.0",
17
17
  "ws": "^8.18.0",