@qwik.dev/router 2.0.0-beta.37 → 2.0.0-beta.39

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 (35) hide show
  1. package/lib/adapters/cloudflare-pages/vite/index.mjs +2 -2
  2. package/lib/adapters/shared/vite/index.d.ts +3 -4
  3. package/lib/adapters/shared/vite/index.mjs +158 -143
  4. package/lib/chunks/dev-preloaded-route-loader.mjs +3 -0
  5. package/lib/chunks/fs.mjs +6 -2
  6. package/lib/chunks/head.qwik.mjs +814 -93
  7. package/lib/chunks/request-body-limit.mjs +37 -0
  8. package/lib/chunks/request-path.mjs +2 -2
  9. package/lib/chunks/routes.mjs +47 -0
  10. package/lib/chunks/server-error.mjs +19 -0
  11. package/lib/chunks/system.mjs +2 -1
  12. package/lib/chunks/use-functions.qwik.mjs +1 -1
  13. package/lib/chunks/{worker-thread.qwik.mjs → user-response.mjs} +1053 -1749
  14. package/lib/chunks/worker-thread.mjs +317 -0
  15. package/lib/index.d.ts +89 -55
  16. package/lib/index.qwik.mjs +178 -100
  17. package/lib/middleware/azure-swa/index.mjs +13 -9
  18. package/lib/middleware/cloudflare-pages/index.mjs +2 -2
  19. package/lib/middleware/deno/index.d.ts +2 -0
  20. package/lib/middleware/deno/index.mjs +2 -1
  21. package/lib/middleware/netlify-edge/index.mjs +2 -2
  22. package/lib/middleware/node/index.d.ts +9 -1
  23. package/lib/middleware/node/index.mjs +28 -3
  24. package/lib/middleware/request-handler/index.d.ts +9 -10
  25. package/lib/middleware/request-handler/index.mjs +26 -1105
  26. package/lib/middleware/vercel-edge/index.mjs +2 -2
  27. package/lib/ssg/index.d.ts +2 -10
  28. package/lib/ssg/index.mjs +10 -50
  29. package/lib/vite/index.d.ts +8 -0
  30. package/lib/vite/index.mjs +406 -117
  31. package/package.json +5 -4
  32. package/lib/chunks/action-handler.mjs +0 -782
  33. package/lib/chunks/deepFreeze.qwik.mjs +0 -608
  34. package/lib/chunks/error-handler.mjs +0 -57
  35. package/lib/chunks/not-found-wrapper.qwik.mjs +0 -25
@@ -5,7 +5,9 @@ import { createReadStream } from 'node:fs';
5
5
  import { join, basename, extname } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { n as normalizeRequestUrl, M as MIME_TYPES } from '../../chunks/url.mjs';
8
+ import { d as devPreloadedRouteLoaders } from '../../chunks/dev-preloaded-route-loader.mjs';
8
9
  import { Http2ServerRequest } from 'node:http2';
10
+ import { D as DEFAULT_REQUEST_BODY_LIMIT, v as validateRequestBodyLimit, R as RequestBodyLimitError } from '../../chunks/request-body-limit.mjs';
9
11
 
10
12
  function fallbackOrigin(req) {
11
13
  const { PROTOCOL_HEADER, HOST_HEADER } = process.env;
@@ -184,7 +186,8 @@ function createNodeResponseSink(res) {
184
186
  close
185
187
  };
186
188
  }
187
- async function fromNodeHttp(url, req, res, mode, getClientConn) {
189
+ async function fromNodeHttp(url, req, res, mode, getClientConn, requestBodyLimit = DEFAULT_REQUEST_BODY_LIMIT) {
190
+ validateRequestBodyLimit(requestBodyLimit);
188
191
  const requestHeaders = new Headers();
189
192
  const nodeRequestHeaders = req.headers;
190
193
  try {
@@ -204,7 +207,14 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
204
207
  console.error(err);
205
208
  }
206
209
  const getRequestBody = async function* () {
210
+ let received = 0;
207
211
  for await (const chunk of req) {
212
+ const byteLength = typeof chunk === "string" ? Buffer.byteLength(chunk) : chunk.byteLength;
213
+ if (byteLength > requestBodyLimit - received) {
214
+ req.resume();
215
+ throw new RequestBodyLimitError(requestBodyLimit);
216
+ }
217
+ received += byteLength;
208
218
  yield chunk;
209
219
  }
210
220
  };
@@ -280,13 +290,28 @@ function createQwikRouter(opts) {
280
290
  setServerPlatform(opts.manifest);
281
291
  }
282
292
  const staticFolder = opts.static?.root ?? join(fileURLToPath(import.meta.url), "..", "..", "dist");
283
- const router = async (req, res, next) => {
293
+ const router = async (req, res, next, limits = {}) => {
284
294
  try {
285
295
  const origin = computeOrigin(req, opts);
286
- const serverRequestEv = await fromNodeHttp(getUrl(req, origin), req, res, "server", opts.getClientConn);
296
+ let requestBodyLimit = opts.requestBodyLimit;
297
+ if (limits?.bodyLimit !== void 0) {
298
+ if (requestBodyLimit === void 0) {
299
+ requestBodyLimit = limits.bodyLimit;
300
+ } else {
301
+ requestBodyLimit = Math.min(requestBodyLimit, limits.bodyLimit);
302
+ }
303
+ }
304
+ const serverRequestEv = await fromNodeHttp(getUrl(req, origin), req, res, "server", opts.getClientConn, requestBodyLimit);
287
305
  if (isDev && opts.platform) {
288
306
  Object.assign(serverRequestEv.platform, opts.platform);
289
307
  }
308
+ if (isDev) {
309
+ const loader = devPreloadedRouteLoaders.get(req);
310
+ if (loader) {
311
+ devPreloadedRouteLoaders.set(serverRequestEv.request, loader);
312
+ devPreloadedRouteLoaders.delete(req);
313
+ }
314
+ }
290
315
  const handled = await requestHandler(serverRequestEv, opts);
291
316
  if (handled) {
292
317
  const err = await handled.completion;
@@ -14,6 +14,8 @@ import type { ValueOrPromise } from '@qwik.dev/core';
14
14
 
15
15
  /** @public */
16
16
  export declare class AbortMessage {
17
+ /** Type-only brand so `Exclude<>` can drop control-flow signals from resolved loader/action data. */
18
+ readonly __controlFlow: true;
17
19
  }
18
20
 
19
21
  /** @internal */
@@ -339,6 +341,8 @@ declare type DocumentStyle = Readonly<((Omit<QwikIntrinsicElements['style'], 'da
339
341
  style?: never;
340
342
  })>;
341
343
 
344
+ declare type EndpointModuleLoader = () => ValueOrPromise<RouteModule>;
345
+
342
346
  /** @public */
343
347
  export declare interface EnvGetter {
344
348
  get(key: string): string | undefined;
@@ -349,13 +353,6 @@ declare type ErrorCodes = ClientErrorCode | ServerErrorCode;
349
353
  /** @public */
350
354
  export declare function getErrorHtml(status: number, e: any): string;
351
355
 
352
- /**
353
- * Return the HTML for a 404 page.
354
- *
355
- * @internal
356
- */
357
- export declare function getNotFound(prefix: string): string;
358
-
359
356
  /**
360
357
  * HTTP Informational Status Codes Status codes in the 1xx range indicate that the server has
361
358
  * received and is processing the request, but no response is available yet.
@@ -396,8 +393,8 @@ declare interface LoadedRoute {
396
393
  $routeBundleNames$?: string[] | undefined;
397
394
  /** Whether this route is a not-found (404) route */
398
395
  $notFound$?: boolean;
399
- /** The error module loader (nearest _E ancestor), for rendering ServerErrors */
400
- $errorLoader$?: ContentModuleLoader;
396
+ /** The nearest _E (error.tsx) boundary's chain to render on a thrown ServerError (in its layouts). */
397
+ $errorLoader$?: ModuleLoader[];
401
398
  /** Merged array of routeLoader$ hashes from all matched nodes (layouts + page) */
402
399
  $loaders$?: string[];
403
400
  /** Runtime-only mapping of routeLoader$ hashes to the matched pathname used for q-loader fetches */
@@ -407,6 +404,8 @@ declare interface LoadedRoute {
407
404
  /** @public */
408
405
  export declare const mergeHeadersCookies: (headers: Headers, cookies: Cookie) => Headers;
409
406
 
407
+ declare type ModuleLoader = ContentModuleLoader | EndpointModuleLoader;
408
+
410
409
  /** @public */
411
410
  declare type PageModule = RouteModule & {
412
411
  readonly default: (props: Record<string, never>) => JSXOutput;
@@ -660,7 +659,7 @@ declare const RequestEvMode: unique symbol;
660
659
  declare const RequestEvRoute: unique symbol;
661
660
 
662
661
  /** @public */
663
- export declare type RequestHandler<PLATFORM = QwikRouterPlatform> = (ev: RequestEvent<PLATFORM>) => Promise<void> | void;
662
+ export declare type RequestHandler<PLATFORM = QwikRouterPlatform> = (ev: RequestEvent<PLATFORM>) => Promise<void | AbortMessage | ServerError> | void | AbortMessage | ServerError;
664
663
 
665
664
  /**
666
665
  * The request handler for QwikRouter. Called by every adapter.