@qwik.dev/router 2.0.0-alpha.7 → 2.0.0-alpha.9
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.
- package/lib/index.d.ts +11 -2
- package/lib/index.qwik.cjs +18 -4
- package/lib/index.qwik.mjs +21 -7
- package/lib/middleware/aws-lambda/index.d.ts +3 -5
- package/lib/middleware/cloudflare-pages/index.d.ts +2 -2
- package/lib/middleware/node/index.d.ts +0 -2
- package/lib/middleware/request-handler/index.cjs +21 -32
- package/lib/middleware/request-handler/index.d.ts +4 -9
- package/lib/middleware/request-handler/index.mjs +21 -32
- package/lib/static/index.d.ts +0 -2
- package/lib/vite/index.cjs +21 -32
- package/lib/vite/index.mjs +21 -32
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -277,6 +277,14 @@ export declare interface DocumentStyle {
|
|
|
277
277
|
|
|
278
278
|
declare type EndpointModuleLoader = () => Promise<RouteModule>;
|
|
279
279
|
|
|
280
|
+
/** @public */
|
|
281
|
+
export declare const ErrorBoundary: Component<ErrorBoundaryProps>;
|
|
282
|
+
|
|
283
|
+
/** @public */
|
|
284
|
+
declare interface ErrorBoundaryProps {
|
|
285
|
+
fallback$?: QRL<(error: any) => any>;
|
|
286
|
+
}
|
|
287
|
+
|
|
280
288
|
declare type Failed = {
|
|
281
289
|
failed: true;
|
|
282
290
|
};
|
|
@@ -419,7 +427,8 @@ declare type MenuModuleLoader = () => Promise<MenuModule>;
|
|
|
419
427
|
declare type ModuleLoader = ContentModuleLoader | EndpointModuleLoader;
|
|
420
428
|
|
|
421
429
|
/** @public */
|
|
422
|
-
|
|
430
|
+
declare type NavigationType_2 = 'initial' | 'form' | 'link' | 'popstate';
|
|
431
|
+
export { NavigationType_2 as NavigationType }
|
|
423
432
|
|
|
424
433
|
/**
|
|
425
434
|
* Creates a new object from `obj` by omitting a set of `keys`.
|
|
@@ -587,7 +596,7 @@ declare interface RouteModule<BODY = unknown> {
|
|
|
587
596
|
|
|
588
597
|
/** @public */
|
|
589
598
|
export declare type RouteNavigate = QRL<(path?: string | number | URL, options?: {
|
|
590
|
-
type?: Exclude<
|
|
599
|
+
type?: Exclude<NavigationType_2, 'initial'>;
|
|
591
600
|
forceReload?: boolean;
|
|
592
601
|
replaceState?: boolean;
|
|
593
602
|
scroll?: boolean;
|
package/lib/index.qwik.cjs
CHANGED
|
@@ -23,6 +23,18 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
const qwikRouterConfig__namespace = /* @__PURE__ */ _interopNamespaceDefault(qwikRouterConfig);
|
|
26
|
+
const ErrorBoundary = core.component$((props) => {
|
|
27
|
+
const store2 = core.useErrorBoundary();
|
|
28
|
+
core.useOnWindow("qerror", core.$((e) => {
|
|
29
|
+
store2.error = e.detail.error;
|
|
30
|
+
}));
|
|
31
|
+
if (store2.error && props.fallback$) {
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
33
|
+
children: props.fallback$(store2.error)
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return /* @__PURE__ */ jsxRuntime.jsx(core.Slot, {});
|
|
37
|
+
});
|
|
26
38
|
const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
27
39
|
const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
|
|
28
40
|
const PREFETCHED_NAVIGATE_PATHS = /* @__PURE__ */ new Set();
|
|
@@ -1420,7 +1432,7 @@ const routeLoaderQrl = (loaderQrl, ...rest) => {
|
|
|
1420
1432
|
If your are managing reusable logic or a library it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception.
|
|
1421
1433
|
For more information check: https://qwik.dev/docs/re-exporting-loaders/`);
|
|
1422
1434
|
}
|
|
1423
|
-
return internal.
|
|
1435
|
+
return internal._wrapStore(state, id);
|
|
1424
1436
|
});
|
|
1425
1437
|
}
|
|
1426
1438
|
loader.__brand = "server_loader";
|
|
@@ -1598,6 +1610,7 @@ const serverQrl = (qrl, options) => {
|
|
|
1598
1610
|
headers: {
|
|
1599
1611
|
...headers,
|
|
1600
1612
|
"Content-Type": "application/qwik-json",
|
|
1613
|
+
Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
|
|
1601
1614
|
// Required so we don't call accidentally
|
|
1602
1615
|
"X-QRL": qrlHash
|
|
1603
1616
|
},
|
|
@@ -1629,19 +1642,19 @@ const serverQrl = (qrl, options) => {
|
|
|
1629
1642
|
} else if (contentType === "application/qwik-json") {
|
|
1630
1643
|
const str = await res.text();
|
|
1631
1644
|
const [obj] = internal._deserialize(str, ctxElm ?? document.documentElement);
|
|
1632
|
-
if (res.status >=
|
|
1645
|
+
if (res.status >= 400) {
|
|
1633
1646
|
throw obj;
|
|
1634
1647
|
}
|
|
1635
1648
|
return obj;
|
|
1636
1649
|
} else if (contentType === "application/json") {
|
|
1637
1650
|
const obj = await res.json();
|
|
1638
|
-
if (res.status >=
|
|
1651
|
+
if (res.status >= 400) {
|
|
1639
1652
|
throw obj;
|
|
1640
1653
|
}
|
|
1641
1654
|
return obj;
|
|
1642
1655
|
} else if (contentType === "text/plain" || contentType === "text/html") {
|
|
1643
1656
|
const str = await res.text();
|
|
1644
|
-
if (res.status >=
|
|
1657
|
+
if (res.status >= 400) {
|
|
1645
1658
|
throw str;
|
|
1646
1659
|
}
|
|
1647
1660
|
return str;
|
|
@@ -1837,6 +1850,7 @@ Object.defineProperty(exports, "z", {
|
|
|
1837
1850
|
enumerable: true,
|
|
1838
1851
|
get: () => zod.z
|
|
1839
1852
|
});
|
|
1853
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
1840
1854
|
exports.Form = Form;
|
|
1841
1855
|
exports.Link = Link;
|
|
1842
1856
|
exports.QWIK_CITY_SCROLLER = QWIK_CITY_SCROLLER;
|
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import { jsx,
|
|
2
|
-
import { isBrowser, createContextId, implicit$FirstArg, useContext, useVisibleTask$, noSerialize, useServerData,
|
|
3
|
-
import { _deserialize, _weakSerialize, _getContextElement, _waitUntilRendered, _getQContainerElement,
|
|
1
|
+
import { jsx, Fragment, jsxs } from "@qwik.dev/core/jsx-runtime";
|
|
2
|
+
import { component$, useErrorBoundary, useOnWindow, $, Slot, isBrowser, createContextId, implicit$FirstArg, useContext, useVisibleTask$, noSerialize, useServerData, untrack, sync$, isDev, withLocale, event$, useStyles$, useStore, useSignal, useContextProvider, useTask$, isServer, getLocale, jsx as jsx$1, SkipRender } from "@qwik.dev/core";
|
|
3
|
+
import { _deserialize, _weakSerialize, _getContextElement, _waitUntilRendered, _getQContainerElement, _wrapStore, _getContextEvent, _serialize } from "@qwik.dev/core/internal";
|
|
4
4
|
import * as qwikRouterConfig from "@qwik-router-config";
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { z as z2 } from "zod";
|
|
7
7
|
import swRegister from "@qwik-router-sw-register";
|
|
8
|
+
const ErrorBoundary = component$((props) => {
|
|
9
|
+
const store2 = useErrorBoundary();
|
|
10
|
+
useOnWindow("qerror", $((e) => {
|
|
11
|
+
store2.error = e.detail.error;
|
|
12
|
+
}));
|
|
13
|
+
if (store2.error && props.fallback$) {
|
|
14
|
+
return /* @__PURE__ */ jsx(Fragment, {
|
|
15
|
+
children: props.fallback$(store2.error)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return /* @__PURE__ */ jsx(Slot, {});
|
|
19
|
+
});
|
|
8
20
|
const MODULE_CACHE = /* @__PURE__ */ new WeakMap();
|
|
9
21
|
const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
|
|
10
22
|
const PREFETCHED_NAVIGATE_PATHS = /* @__PURE__ */ new Set();
|
|
@@ -1402,7 +1414,7 @@ const routeLoaderQrl = (loaderQrl, ...rest) => {
|
|
|
1402
1414
|
If your are managing reusable logic or a library it is essential that this function is re-exported from within 'layout.tsx' or 'index.tsx file of the existing route otherwise it will not run or throw exception.
|
|
1403
1415
|
For more information check: https://qwik.dev/docs/re-exporting-loaders/`);
|
|
1404
1416
|
}
|
|
1405
|
-
return
|
|
1417
|
+
return _wrapStore(state, id);
|
|
1406
1418
|
});
|
|
1407
1419
|
}
|
|
1408
1420
|
loader.__brand = "server_loader";
|
|
@@ -1580,6 +1592,7 @@ const serverQrl = (qrl, options) => {
|
|
|
1580
1592
|
headers: {
|
|
1581
1593
|
...headers,
|
|
1582
1594
|
"Content-Type": "application/qwik-json",
|
|
1595
|
+
Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
|
|
1583
1596
|
// Required so we don't call accidentally
|
|
1584
1597
|
"X-QRL": qrlHash
|
|
1585
1598
|
},
|
|
@@ -1611,19 +1624,19 @@ const serverQrl = (qrl, options) => {
|
|
|
1611
1624
|
} else if (contentType === "application/qwik-json") {
|
|
1612
1625
|
const str = await res.text();
|
|
1613
1626
|
const [obj] = _deserialize(str, ctxElm ?? document.documentElement);
|
|
1614
|
-
if (res.status >=
|
|
1627
|
+
if (res.status >= 400) {
|
|
1615
1628
|
throw obj;
|
|
1616
1629
|
}
|
|
1617
1630
|
return obj;
|
|
1618
1631
|
} else if (contentType === "application/json") {
|
|
1619
1632
|
const obj = await res.json();
|
|
1620
|
-
if (res.status >=
|
|
1633
|
+
if (res.status >= 400) {
|
|
1621
1634
|
throw obj;
|
|
1622
1635
|
}
|
|
1623
1636
|
return obj;
|
|
1624
1637
|
} else if (contentType === "text/plain" || contentType === "text/html") {
|
|
1625
1638
|
const str = await res.text();
|
|
1626
|
-
if (res.status >=
|
|
1639
|
+
if (res.status >= 400) {
|
|
1627
1640
|
throw str;
|
|
1628
1641
|
}
|
|
1629
1642
|
return str;
|
|
@@ -1816,6 +1829,7 @@ function omitProps(obj, keys) {
|
|
|
1816
1829
|
return omittedObj;
|
|
1817
1830
|
}
|
|
1818
1831
|
export {
|
|
1832
|
+
ErrorBoundary,
|
|
1819
1833
|
Form,
|
|
1820
1834
|
Link,
|
|
1821
1835
|
QWIK_CITY_SCROLLER,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
|
|
3
1
|
import { Http2ServerRequest } from 'http2';
|
|
4
2
|
import { IncomingMessage } from 'http';
|
|
5
3
|
import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
@@ -27,9 +25,9 @@ export declare const createQwikCity: typeof createQwikRouter;
|
|
|
27
25
|
/** @public */
|
|
28
26
|
export declare function createQwikRouter(opts: AwsOpt): {
|
|
29
27
|
fixPath: (pathT: string) => string;
|
|
30
|
-
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse
|
|
31
|
-
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse
|
|
32
|
-
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse
|
|
28
|
+
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
29
|
+
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
30
|
+
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
33
31
|
handle: (req: any, res: any) => void;
|
|
34
32
|
};
|
|
35
33
|
|
|
@@ -7,11 +7,11 @@ import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-ha
|
|
|
7
7
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
|
-
export declare function createQwikRouter(opts: QwikRouterCloudflarePagesOptions): (request: PlatformCloudflarePages[
|
|
10
|
+
export declare function createQwikRouter(opts: QwikRouterCloudflarePagesOptions): (request: PlatformCloudflarePages["request"], env: PlatformCloudflarePages["env"] & {
|
|
11
11
|
ASSETS: {
|
|
12
12
|
fetch: (req: Request) => Response;
|
|
13
13
|
};
|
|
14
|
-
}, ctx: PlatformCloudflarePages[
|
|
14
|
+
}, ctx: PlatformCloudflarePages["ctx"]) => Promise<Response>;
|
|
15
15
|
|
|
16
16
|
/** @public */
|
|
17
17
|
export declare interface PlatformCloudflarePages {
|
|
@@ -43,17 +43,11 @@ module.exports = __toCommonJS(request_handler_exports);
|
|
|
43
43
|
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
44
44
|
var ServerError = class extends Error {
|
|
45
45
|
constructor(status, data) {
|
|
46
|
-
super();
|
|
46
|
+
super(typeof data === "string" ? data : void 0);
|
|
47
47
|
this.status = status;
|
|
48
48
|
this.data = data;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var ErrorResponse = class extends Error {
|
|
52
|
-
constructor(status, message) {
|
|
53
|
-
super(message);
|
|
54
|
-
this.status = status;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
51
|
function getErrorHtml(status, e) {
|
|
58
52
|
let message = "Server Error";
|
|
59
53
|
if (e != null) {
|
|
@@ -584,12 +578,18 @@ async function runNext(requestEv, resolve) {
|
|
|
584
578
|
if (e instanceof RedirectMessage) {
|
|
585
579
|
const stream = requestEv.getWritableStream();
|
|
586
580
|
await stream.close();
|
|
587
|
-
} else if (e instanceof
|
|
588
|
-
console.error(e);
|
|
581
|
+
} else if (e instanceof ServerError) {
|
|
589
582
|
if (!requestEv.headersSent) {
|
|
590
|
-
const html = getErrorHtml(e.status, e);
|
|
591
583
|
const status = e.status;
|
|
592
|
-
requestEv.
|
|
584
|
+
const accept = requestEv.request.headers.get("Accept");
|
|
585
|
+
if (accept && !accept.includes("text/html")) {
|
|
586
|
+
const qwikSerializer = requestEv[RequestEvQwikSerializer];
|
|
587
|
+
requestEv.headers.set("Content-Type", "application/qwik-json");
|
|
588
|
+
requestEv.send(status, await qwikSerializer._serialize([e.data]));
|
|
589
|
+
} else {
|
|
590
|
+
const html = getErrorHtml(e.status, e.data);
|
|
591
|
+
requestEv.html(status, html);
|
|
592
|
+
}
|
|
593
593
|
}
|
|
594
594
|
} else if (!(e instanceof AbortMessage)) {
|
|
595
595
|
if (getRequestMode(requestEv) !== "dev") {
|
|
@@ -782,7 +782,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
|
|
|
782
782
|
},
|
|
783
783
|
error: (statusCode, message) => {
|
|
784
784
|
status = statusCode;
|
|
785
|
-
return new
|
|
785
|
+
return new ServerError(statusCode, message);
|
|
786
786
|
},
|
|
787
787
|
redirect: (statusCode, url2) => {
|
|
788
788
|
check();
|
|
@@ -883,7 +883,7 @@ var parseRequest = async ({ request, method, query }, sharedMap, qwikSerializer)
|
|
|
883
883
|
if (data) {
|
|
884
884
|
try {
|
|
885
885
|
return qwikSerializer._deserialize(decodeURIComponent(data));
|
|
886
|
-
} catch
|
|
886
|
+
} catch {
|
|
887
887
|
}
|
|
888
888
|
}
|
|
889
889
|
}
|
|
@@ -1182,25 +1182,14 @@ async function pureServerFunction(ev) {
|
|
|
1182
1182
|
const [qrl, ...args] = data;
|
|
1183
1183
|
if (isQrl(qrl) && qrl.getHash() === fn) {
|
|
1184
1184
|
let result;
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
result = await qrl.apply(ev, args);
|
|
1194
|
-
}
|
|
1195
|
-
} catch (err) {
|
|
1196
|
-
if (err instanceof ServerError) {
|
|
1197
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
1198
|
-
ev.send(err.status, await qwikSerializer._serialize([err.data]));
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
1202
|
-
ev.send(500, await qwikSerializer._serialize([err]));
|
|
1203
|
-
return;
|
|
1185
|
+
if (isDev) {
|
|
1186
|
+
result = await measure(
|
|
1187
|
+
ev,
|
|
1188
|
+
`server_${qrl.getSymbol()}`,
|
|
1189
|
+
() => qrl.apply(ev, args)
|
|
1190
|
+
);
|
|
1191
|
+
} else {
|
|
1192
|
+
result = await qrl.apply(ev, args);
|
|
1204
1193
|
}
|
|
1205
1194
|
if (isAsyncIterator(result)) {
|
|
1206
1195
|
ev.headers.set("Content-Type", "text/qwik-json-stream");
|
|
@@ -100,7 +100,7 @@ export declare interface ClientConn {
|
|
|
100
100
|
* HTTP Client Error Status Codes Status codes in the 4xx range indicate that the client's request
|
|
101
101
|
* was malformed or invalid and could not be understood or processed by the server.
|
|
102
102
|
*/
|
|
103
|
-
declare type ClientErrorCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451;
|
|
103
|
+
declare type ClientErrorCode = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 499;
|
|
104
104
|
|
|
105
105
|
/** @public */
|
|
106
106
|
declare interface ContentHeading {
|
|
@@ -286,11 +286,6 @@ export declare interface EnvGetter {
|
|
|
286
286
|
|
|
287
287
|
declare type ErrorCodes = ClientErrorCode | ServerErrorCode;
|
|
288
288
|
|
|
289
|
-
declare class ErrorResponse extends Error {
|
|
290
|
-
status: number;
|
|
291
|
-
constructor(status: number, message?: string);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
289
|
/** @public */
|
|
295
290
|
export declare function getErrorHtml(status: number, e: any): string;
|
|
296
291
|
|
|
@@ -486,7 +481,7 @@ export declare interface RequestEventCommon<PLATFORM = QwikRouterPlatform> exten
|
|
|
486
481
|
* to end a response with `404`, and use the 404 handler in the routes directory. See
|
|
487
482
|
* https://developer.mozilla.org/en-US/docs/Web/HTTP/Status for which status code should be used.
|
|
488
483
|
*/
|
|
489
|
-
readonly error: (statusCode: ErrorCodes, message:
|
|
484
|
+
readonly error: <T = any>(statusCode: ErrorCodes, message: T) => ServerError<T>;
|
|
490
485
|
/**
|
|
491
486
|
* Convenience method to send an text body response. The response will be automatically set the
|
|
492
487
|
* `Content-Type` header to`text/plain; charset=utf-8`. An `text()` response can only be called
|
|
@@ -594,7 +589,7 @@ declare interface SendMethod {
|
|
|
594
589
|
}
|
|
595
590
|
|
|
596
591
|
/** @public */
|
|
597
|
-
export declare class ServerError<T =
|
|
592
|
+
export declare class ServerError<T = any> extends Error {
|
|
598
593
|
status: number;
|
|
599
594
|
data: T;
|
|
600
595
|
constructor(status: number, data: T);
|
|
@@ -673,7 +668,7 @@ declare type SuccessCode = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 |
|
|
|
673
668
|
export declare class _TextEncoderStream_polyfill {
|
|
674
669
|
#private;
|
|
675
670
|
get encoding(): string;
|
|
676
|
-
get readable(): ReadableStream<Uint8Array
|
|
671
|
+
get readable(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
677
672
|
get writable(): WritableStream<string>;
|
|
678
673
|
get [Symbol.toStringTag](): string;
|
|
679
674
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
2
2
|
var ServerError = class extends Error {
|
|
3
3
|
constructor(status, data) {
|
|
4
|
-
super();
|
|
4
|
+
super(typeof data === "string" ? data : void 0);
|
|
5
5
|
this.status = status;
|
|
6
6
|
this.data = data;
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
|
-
var ErrorResponse = class extends Error {
|
|
10
|
-
constructor(status, message) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.status = status;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
9
|
function getErrorHtml(status, e) {
|
|
16
10
|
let message = "Server Error";
|
|
17
11
|
if (e != null) {
|
|
@@ -542,12 +536,18 @@ async function runNext(requestEv, resolve) {
|
|
|
542
536
|
if (e instanceof RedirectMessage) {
|
|
543
537
|
const stream = requestEv.getWritableStream();
|
|
544
538
|
await stream.close();
|
|
545
|
-
} else if (e instanceof
|
|
546
|
-
console.error(e);
|
|
539
|
+
} else if (e instanceof ServerError) {
|
|
547
540
|
if (!requestEv.headersSent) {
|
|
548
|
-
const html = getErrorHtml(e.status, e);
|
|
549
541
|
const status = e.status;
|
|
550
|
-
requestEv.
|
|
542
|
+
const accept = requestEv.request.headers.get("Accept");
|
|
543
|
+
if (accept && !accept.includes("text/html")) {
|
|
544
|
+
const qwikSerializer = requestEv[RequestEvQwikSerializer];
|
|
545
|
+
requestEv.headers.set("Content-Type", "application/qwik-json");
|
|
546
|
+
requestEv.send(status, await qwikSerializer._serialize([e.data]));
|
|
547
|
+
} else {
|
|
548
|
+
const html = getErrorHtml(e.status, e.data);
|
|
549
|
+
requestEv.html(status, html);
|
|
550
|
+
}
|
|
551
551
|
}
|
|
552
552
|
} else if (!(e instanceof AbortMessage)) {
|
|
553
553
|
if (getRequestMode(requestEv) !== "dev") {
|
|
@@ -740,7 +740,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
|
|
|
740
740
|
},
|
|
741
741
|
error: (statusCode, message) => {
|
|
742
742
|
status = statusCode;
|
|
743
|
-
return new
|
|
743
|
+
return new ServerError(statusCode, message);
|
|
744
744
|
},
|
|
745
745
|
redirect: (statusCode, url2) => {
|
|
746
746
|
check();
|
|
@@ -841,7 +841,7 @@ var parseRequest = async ({ request, method, query }, sharedMap, qwikSerializer)
|
|
|
841
841
|
if (data) {
|
|
842
842
|
try {
|
|
843
843
|
return qwikSerializer._deserialize(decodeURIComponent(data));
|
|
844
|
-
} catch
|
|
844
|
+
} catch {
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
847
|
}
|
|
@@ -1140,25 +1140,14 @@ async function pureServerFunction(ev) {
|
|
|
1140
1140
|
const [qrl, ...args] = data;
|
|
1141
1141
|
if (isQrl(qrl) && qrl.getHash() === fn) {
|
|
1142
1142
|
let result;
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
result = await qrl.apply(ev, args);
|
|
1152
|
-
}
|
|
1153
|
-
} catch (err) {
|
|
1154
|
-
if (err instanceof ServerError) {
|
|
1155
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
1156
|
-
ev.send(err.status, await qwikSerializer._serialize([err.data]));
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
1160
|
-
ev.send(500, await qwikSerializer._serialize([err]));
|
|
1161
|
-
return;
|
|
1143
|
+
if (isDev) {
|
|
1144
|
+
result = await measure(
|
|
1145
|
+
ev,
|
|
1146
|
+
`server_${qrl.getSymbol()}`,
|
|
1147
|
+
() => qrl.apply(ev, args)
|
|
1148
|
+
);
|
|
1149
|
+
} else {
|
|
1150
|
+
result = await qrl.apply(ev, args);
|
|
1162
1151
|
}
|
|
1163
1152
|
if (isAsyncIterator(result)) {
|
|
1164
1153
|
ev.headers.set("Content-Type", "text/qwik-json-stream");
|
package/lib/static/index.d.ts
CHANGED
package/lib/vite/index.cjs
CHANGED
|
@@ -14306,17 +14306,11 @@ var import_vite2 = require("vite");
|
|
|
14306
14306
|
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
14307
14307
|
var ServerError = class extends Error {
|
|
14308
14308
|
constructor(status, data) {
|
|
14309
|
-
super();
|
|
14309
|
+
super(typeof data === "string" ? data : void 0);
|
|
14310
14310
|
this.status = status;
|
|
14311
14311
|
this.data = data;
|
|
14312
14312
|
}
|
|
14313
14313
|
};
|
|
14314
|
-
var ErrorResponse = class extends Error {
|
|
14315
|
-
constructor(status, message) {
|
|
14316
|
-
super(message);
|
|
14317
|
-
this.status = status;
|
|
14318
|
-
}
|
|
14319
|
-
};
|
|
14320
14314
|
function getErrorHtml(status, e) {
|
|
14321
14315
|
let message = "Server Error";
|
|
14322
14316
|
if (e != null) {
|
|
@@ -14764,12 +14758,18 @@ async function runNext(requestEv, resolve4) {
|
|
|
14764
14758
|
if (e instanceof RedirectMessage) {
|
|
14765
14759
|
const stream = requestEv.getWritableStream();
|
|
14766
14760
|
await stream.close();
|
|
14767
|
-
} else if (e instanceof
|
|
14768
|
-
console.error(e);
|
|
14761
|
+
} else if (e instanceof ServerError) {
|
|
14769
14762
|
if (!requestEv.headersSent) {
|
|
14770
|
-
const html5 = getErrorHtml(e.status, e);
|
|
14771
14763
|
const status = e.status;
|
|
14772
|
-
requestEv.
|
|
14764
|
+
const accept = requestEv.request.headers.get("Accept");
|
|
14765
|
+
if (accept && !accept.includes("text/html")) {
|
|
14766
|
+
const qwikSerializer = requestEv[RequestEvQwikSerializer];
|
|
14767
|
+
requestEv.headers.set("Content-Type", "application/qwik-json");
|
|
14768
|
+
requestEv.send(status, await qwikSerializer._serialize([e.data]));
|
|
14769
|
+
} else {
|
|
14770
|
+
const html5 = getErrorHtml(e.status, e.data);
|
|
14771
|
+
requestEv.html(status, html5);
|
|
14772
|
+
}
|
|
14773
14773
|
}
|
|
14774
14774
|
} else if (!(e instanceof AbortMessage)) {
|
|
14775
14775
|
if (getRequestMode(requestEv) !== "dev") {
|
|
@@ -14962,7 +14962,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
|
|
|
14962
14962
|
},
|
|
14963
14963
|
error: (statusCode, message) => {
|
|
14964
14964
|
status = statusCode;
|
|
14965
|
-
return new
|
|
14965
|
+
return new ServerError(statusCode, message);
|
|
14966
14966
|
},
|
|
14967
14967
|
redirect: (statusCode, url2) => {
|
|
14968
14968
|
check();
|
|
@@ -15063,7 +15063,7 @@ var parseRequest = async ({ request, method, query }, sharedMap, qwikSerializer)
|
|
|
15063
15063
|
if (data) {
|
|
15064
15064
|
try {
|
|
15065
15065
|
return qwikSerializer._deserialize(decodeURIComponent(data));
|
|
15066
|
-
} catch
|
|
15066
|
+
} catch {
|
|
15067
15067
|
}
|
|
15068
15068
|
}
|
|
15069
15069
|
}
|
|
@@ -15365,25 +15365,14 @@ async function pureServerFunction(ev) {
|
|
|
15365
15365
|
const [qrl, ...args] = data;
|
|
15366
15366
|
if (isQrl(qrl) && qrl.getHash() === fn) {
|
|
15367
15367
|
let result;
|
|
15368
|
-
|
|
15369
|
-
|
|
15370
|
-
|
|
15371
|
-
|
|
15372
|
-
|
|
15373
|
-
|
|
15374
|
-
|
|
15375
|
-
|
|
15376
|
-
result = await qrl.apply(ev, args);
|
|
15377
|
-
}
|
|
15378
|
-
} catch (err) {
|
|
15379
|
-
if (err instanceof ServerError) {
|
|
15380
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
15381
|
-
ev.send(err.status, await qwikSerializer._serialize([err.data]));
|
|
15382
|
-
return;
|
|
15383
|
-
}
|
|
15384
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
15385
|
-
ev.send(500, await qwikSerializer._serialize([err]));
|
|
15386
|
-
return;
|
|
15368
|
+
if (isDev) {
|
|
15369
|
+
result = await measure(
|
|
15370
|
+
ev,
|
|
15371
|
+
`server_${qrl.getSymbol()}`,
|
|
15372
|
+
() => qrl.apply(ev, args)
|
|
15373
|
+
);
|
|
15374
|
+
} else {
|
|
15375
|
+
result = await qrl.apply(ev, args);
|
|
15387
15376
|
}
|
|
15388
15377
|
if (isAsyncIterator(result)) {
|
|
15389
15378
|
ev.headers.set("Content-Type", "text/qwik-json-stream");
|
package/lib/vite/index.mjs
CHANGED
|
@@ -14295,17 +14295,11 @@ import { loadEnv } from "vite";
|
|
|
14295
14295
|
// packages/qwik-router/src/middleware/request-handler/error-handler.ts
|
|
14296
14296
|
var ServerError = class extends Error {
|
|
14297
14297
|
constructor(status, data) {
|
|
14298
|
-
super();
|
|
14298
|
+
super(typeof data === "string" ? data : void 0);
|
|
14299
14299
|
this.status = status;
|
|
14300
14300
|
this.data = data;
|
|
14301
14301
|
}
|
|
14302
14302
|
};
|
|
14303
|
-
var ErrorResponse = class extends Error {
|
|
14304
|
-
constructor(status, message) {
|
|
14305
|
-
super(message);
|
|
14306
|
-
this.status = status;
|
|
14307
|
-
}
|
|
14308
|
-
};
|
|
14309
14303
|
function getErrorHtml(status, e) {
|
|
14310
14304
|
let message = "Server Error";
|
|
14311
14305
|
if (e != null) {
|
|
@@ -14753,12 +14747,18 @@ async function runNext(requestEv, resolve4) {
|
|
|
14753
14747
|
if (e instanceof RedirectMessage) {
|
|
14754
14748
|
const stream = requestEv.getWritableStream();
|
|
14755
14749
|
await stream.close();
|
|
14756
|
-
} else if (e instanceof
|
|
14757
|
-
console.error(e);
|
|
14750
|
+
} else if (e instanceof ServerError) {
|
|
14758
14751
|
if (!requestEv.headersSent) {
|
|
14759
|
-
const html5 = getErrorHtml(e.status, e);
|
|
14760
14752
|
const status = e.status;
|
|
14761
|
-
requestEv.
|
|
14753
|
+
const accept = requestEv.request.headers.get("Accept");
|
|
14754
|
+
if (accept && !accept.includes("text/html")) {
|
|
14755
|
+
const qwikSerializer = requestEv[RequestEvQwikSerializer];
|
|
14756
|
+
requestEv.headers.set("Content-Type", "application/qwik-json");
|
|
14757
|
+
requestEv.send(status, await qwikSerializer._serialize([e.data]));
|
|
14758
|
+
} else {
|
|
14759
|
+
const html5 = getErrorHtml(e.status, e.data);
|
|
14760
|
+
requestEv.html(status, html5);
|
|
14761
|
+
}
|
|
14762
14762
|
}
|
|
14763
14763
|
} else if (!(e instanceof AbortMessage)) {
|
|
14764
14764
|
if (getRequestMode(requestEv) !== "dev") {
|
|
@@ -14951,7 +14951,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
|
|
|
14951
14951
|
},
|
|
14952
14952
|
error: (statusCode, message) => {
|
|
14953
14953
|
status = statusCode;
|
|
14954
|
-
return new
|
|
14954
|
+
return new ServerError(statusCode, message);
|
|
14955
14955
|
},
|
|
14956
14956
|
redirect: (statusCode, url2) => {
|
|
14957
14957
|
check();
|
|
@@ -15052,7 +15052,7 @@ var parseRequest = async ({ request, method, query }, sharedMap, qwikSerializer)
|
|
|
15052
15052
|
if (data) {
|
|
15053
15053
|
try {
|
|
15054
15054
|
return qwikSerializer._deserialize(decodeURIComponent(data));
|
|
15055
|
-
} catch
|
|
15055
|
+
} catch {
|
|
15056
15056
|
}
|
|
15057
15057
|
}
|
|
15058
15058
|
}
|
|
@@ -15354,25 +15354,14 @@ async function pureServerFunction(ev) {
|
|
|
15354
15354
|
const [qrl, ...args] = data;
|
|
15355
15355
|
if (isQrl(qrl) && qrl.getHash() === fn) {
|
|
15356
15356
|
let result;
|
|
15357
|
-
|
|
15358
|
-
|
|
15359
|
-
|
|
15360
|
-
|
|
15361
|
-
|
|
15362
|
-
|
|
15363
|
-
|
|
15364
|
-
|
|
15365
|
-
result = await qrl.apply(ev, args);
|
|
15366
|
-
}
|
|
15367
|
-
} catch (err) {
|
|
15368
|
-
if (err instanceof ServerError) {
|
|
15369
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
15370
|
-
ev.send(err.status, await qwikSerializer._serialize([err.data]));
|
|
15371
|
-
return;
|
|
15372
|
-
}
|
|
15373
|
-
ev.headers.set("Content-Type", "application/qwik-json");
|
|
15374
|
-
ev.send(500, await qwikSerializer._serialize([err]));
|
|
15375
|
-
return;
|
|
15357
|
+
if (isDev) {
|
|
15358
|
+
result = await measure(
|
|
15359
|
+
ev,
|
|
15360
|
+
`server_${qrl.getSymbol()}`,
|
|
15361
|
+
() => qrl.apply(ev, args)
|
|
15362
|
+
);
|
|
15363
|
+
} else {
|
|
15364
|
+
result = await qrl.apply(ev, args);
|
|
15376
15365
|
}
|
|
15377
15366
|
if (isAsyncIterator(result)) {
|
|
15378
15367
|
ev.headers.set("Content-Type", "text/qwik-json-stream");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwik.dev/router",
|
|
3
3
|
"description": "The router for Qwik.",
|
|
4
|
-
"version": "2.0.0-alpha.
|
|
4
|
+
"version": "2.0.0-alpha.9",
|
|
5
5
|
"bugs": "https://github.com/QwikDev/qwik/issues",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@mdx-js/mdx": "^3",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@azure/functions": "3.5.1",
|
|
20
|
-
"@microsoft/api-extractor": "7.
|
|
20
|
+
"@microsoft/api-extractor": "7.52.1",
|
|
21
21
|
"@netlify/edge-functions": "2.10.0",
|
|
22
22
|
"@types/mdast": "4.0.4",
|
|
23
23
|
"@types/node": "20.14.11",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"remark-gfm": "4.0.0",
|
|
37
37
|
"set-cookie-parser": "2.6.0",
|
|
38
38
|
"tsm": "2.3.0",
|
|
39
|
-
"typescript": "5.
|
|
39
|
+
"typescript": "5.8.2",
|
|
40
40
|
"unified": "11.0.5",
|
|
41
41
|
"unist-util-visit": "5.0.0",
|
|
42
42
|
"uvu": "0.5.6",
|
|
43
43
|
"yaml": "2.4.5",
|
|
44
|
-
"@qwik.dev/core": "2.0.0-alpha.
|
|
44
|
+
"@qwik.dev/core": "2.0.0-alpha.9"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|