@qwik.dev/router 2.0.0-beta.30 → 2.0.0-beta.32
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/chunks/fs.mjs +1 -1
- package/lib/chunks/routing.qwik.mjs +10 -9
- package/lib/chunks/{mime-types.mjs → url.mjs} +10 -1
- package/lib/chunks/worker-thread.qwik.mjs +35 -34
- package/lib/index.d.ts +4 -3
- package/lib/index.qwik.mjs +277 -264
- package/lib/middleware/aws-lambda/index.d.ts +15 -17
- package/lib/middleware/aws-lambda/index.mjs +4 -8
- package/lib/middleware/azure-swa/index.mjs +0 -4
- package/lib/middleware/bun/index.d.ts +9 -5
- package/lib/middleware/bun/index.mjs +6 -29
- package/lib/middleware/cloudflare-pages/index.mjs +0 -4
- package/lib/middleware/deno/index.d.ts +9 -5
- package/lib/middleware/deno/index.mjs +5 -28
- package/lib/middleware/firebase/index.mjs +3 -8
- package/lib/middleware/netlify-edge/index.mjs +0 -4
- package/lib/middleware/node/index.d.ts +9 -5
- package/lib/middleware/node/index.mjs +4 -25
- package/lib/middleware/request-handler/index.d.ts +4 -7
- package/lib/middleware/request-handler/index.mjs +41 -44
- package/lib/middleware/vercel-edge/index.mjs +0 -4
- package/lib/vite/index.mjs +208 -85
- package/package.json +3 -3
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import { Http2ServerRequest } from 'http2';
|
|
2
|
-
import { IncomingMessage } from 'http';
|
|
3
|
-
import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
4
|
-
import type { QwikCityPlan } from '@qwik.dev/router';
|
|
1
|
+
import type { Http2ServerRequest } from 'node:http2';
|
|
2
|
+
import type { IncomingMessage } from 'node:http';
|
|
3
|
+
import type { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
5
4
|
import type { QwikManifest } from '@qwik.dev/core/optimizer';
|
|
6
|
-
import type { QwikRouterConfig } from '@qwik.dev/router';
|
|
7
5
|
import type { Render } from '@qwik.dev/core/server';
|
|
8
6
|
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
9
|
-
import { ServerResponse } from 'http';
|
|
7
|
+
import type { ServerResponse } from 'node:http';
|
|
10
8
|
|
|
11
9
|
declare interface AwsOpt {
|
|
12
10
|
render: Render;
|
|
13
11
|
manifest?: QwikManifest;
|
|
14
|
-
/** @deprecated Not used */
|
|
15
|
-
qwikRouterConfig?: QwikRouterConfig;
|
|
16
|
-
/** @deprecated Not used */
|
|
17
|
-
qwikCityPlan?: QwikCityPlan;
|
|
18
12
|
}
|
|
19
13
|
|
|
20
14
|
/**
|
|
@@ -24,13 +18,7 @@ declare interface AwsOpt {
|
|
|
24
18
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
25
19
|
|
|
26
20
|
/** @public */
|
|
27
|
-
export declare function createQwikRouter(opts: AwsOpt):
|
|
28
|
-
fixPath: (pathT: string) => string;
|
|
29
|
-
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
30
|
-
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
31
|
-
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
32
|
-
handle: (req: any, res: any) => void;
|
|
33
|
-
};
|
|
21
|
+
export declare function createQwikRouter(opts: AwsOpt): QwikRouterAwsLambdaMiddleware;
|
|
34
22
|
|
|
35
23
|
/** @public */
|
|
36
24
|
export declare interface PlatformAwsLambda extends Object {
|
|
@@ -42,6 +30,16 @@ export declare interface PlatformAwsLambda extends Object {
|
|
|
42
30
|
*/
|
|
43
31
|
export declare type QwikCityAwsLambdaOptions = QwikRouterAwsLambdaOptions;
|
|
44
32
|
|
|
33
|
+
/** @public */
|
|
34
|
+
export declare interface QwikRouterAwsLambdaMiddleware {
|
|
35
|
+
fixPath: (pathT: string) => string;
|
|
36
|
+
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
37
|
+
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
38
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
39
|
+
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
40
|
+
handle: (req: any, res: any) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
45
43
|
/** @public */
|
|
46
44
|
export declare interface QwikRouterAwsLambdaOptions extends ServerRenderOptions {
|
|
47
45
|
}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
|
|
2
2
|
|
|
3
3
|
function createQwikRouter(opts) {
|
|
4
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
5
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
6
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
7
|
-
}
|
|
8
4
|
try {
|
|
9
|
-
const { router, staticFile
|
|
5
|
+
const { router, staticFile } = createQwikRouter$1({
|
|
10
6
|
render: opts.render,
|
|
11
|
-
qwikRouterConfig: opts.qwikRouterConfig,
|
|
12
7
|
manifest: opts.manifest,
|
|
13
8
|
static: {
|
|
14
9
|
cacheControl: "public, max-age=31557600"
|
|
@@ -36,11 +31,12 @@ function createQwikRouter(opts) {
|
|
|
36
31
|
req.url = fixPath(req.url);
|
|
37
32
|
staticFile(req, res, () => {
|
|
38
33
|
router(req, res, () => {
|
|
39
|
-
notFound(req, res, () => {
|
|
40
|
-
});
|
|
41
34
|
});
|
|
42
35
|
});
|
|
43
36
|
};
|
|
37
|
+
const notFound = async (_req, _res, next) => {
|
|
38
|
+
next();
|
|
39
|
+
};
|
|
44
40
|
return {
|
|
45
41
|
fixPath,
|
|
46
42
|
router,
|
|
@@ -3,10 +3,6 @@ import { requestHandler, isStaticPath, getNotFound } from '@qwik.dev/router/midd
|
|
|
3
3
|
import { parseString } from 'set-cookie-parser';
|
|
4
4
|
|
|
5
5
|
function createQwikRouter(opts) {
|
|
6
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
7
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
8
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
9
|
-
}
|
|
10
6
|
if (opts.manifest) {
|
|
11
7
|
setServerPlatform(opts.manifest);
|
|
12
8
|
}
|
|
@@ -8,11 +8,7 @@ import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-ha
|
|
|
8
8
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
|
-
export declare function createQwikRouter(opts: QwikRouterBunOptions):
|
|
12
|
-
router: (request: Request) => Promise<Response | null>;
|
|
13
|
-
notFound: (request: Request) => Promise<Response>;
|
|
14
|
-
staticFile: (request: Request) => Promise<Response | null>;
|
|
15
|
-
};
|
|
11
|
+
export declare function createQwikRouter(opts: QwikRouterBunOptions): QwikRouterBunMiddleware;
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
14
|
* @deprecated Use `QwikRouterBunOptions` instead. Will be removed in V3
|
|
@@ -20,6 +16,14 @@ export declare function createQwikRouter(opts: QwikRouterBunOptions): {
|
|
|
20
16
|
*/
|
|
21
17
|
export declare type QwikCityBunOptions = QwikRouterBunOptions;
|
|
22
18
|
|
|
19
|
+
/** @public */
|
|
20
|
+
export declare interface QwikRouterBunMiddleware {
|
|
21
|
+
router: (request: Request) => Promise<Response | null>;
|
|
22
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
23
|
+
notFound: (request: Request) => Promise<Response>;
|
|
24
|
+
staticFile: (request: Request) => Promise<Response | null>;
|
|
25
|
+
}
|
|
26
|
+
|
|
23
27
|
/** @public */
|
|
24
28
|
export declare interface QwikRouterBunOptions extends ServerRenderOptions {
|
|
25
29
|
/** Options for serving static files */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { isDev } from '@qwik.dev/core/build';
|
|
1
2
|
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
-
import { _TextEncoderStream_polyfill, isStaticPath,
|
|
3
|
+
import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
3
4
|
import { join, extname } from 'node:path';
|
|
4
|
-
import { M as MIME_TYPES } from '../../chunks/
|
|
5
|
-
import { isDev } from '@qwik.dev/core/build';
|
|
5
|
+
import { M as MIME_TYPES, n as normalizeRequestUrl } from '../../chunks/url.mjs';
|
|
6
6
|
|
|
7
7
|
function getRequestUrl(request, opts) {
|
|
8
8
|
const url = new URL(request.url);
|
|
@@ -10,13 +10,9 @@ function getRequestUrl(request, opts) {
|
|
|
10
10
|
if (!origin) {
|
|
11
11
|
return url;
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
14
14
|
}
|
|
15
15
|
function createQwikRouter(opts) {
|
|
16
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
17
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
18
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
19
|
-
}
|
|
20
16
|
globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
|
|
21
17
|
if (opts.manifest) {
|
|
22
18
|
setServerPlatform(opts.manifest);
|
|
@@ -81,27 +77,8 @@ function createQwikRouter(opts) {
|
|
|
81
77
|
});
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
|
-
const notFound = async (
|
|
85
|
-
|
|
86
|
-
const url = getRequestUrl(request, opts);
|
|
87
|
-
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
88
|
-
return new Response(notFoundHtml, {
|
|
89
|
-
status: 404,
|
|
90
|
-
headers: {
|
|
91
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
92
|
-
"X-Not-Found": url.pathname
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
} catch (e) {
|
|
96
|
-
console.error(e);
|
|
97
|
-
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
98
|
-
status: 500,
|
|
99
|
-
headers: {
|
|
100
|
-
"Content-Type": "text/plain; charset=utf-8",
|
|
101
|
-
"X-Error": "bun-server"
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
80
|
+
const notFound = async (_request) => {
|
|
81
|
+
return null;
|
|
105
82
|
};
|
|
106
83
|
const openStaticFile = async (url) => {
|
|
107
84
|
const pathname = url.pathname;
|
|
@@ -3,10 +3,6 @@ import { _TextEncoderStream_polyfill, isStaticPath, mergeHeadersCookies, request
|
|
|
3
3
|
import { isDev } from '@qwik.dev/core/build';
|
|
4
4
|
|
|
5
5
|
function createQwikRouter(opts) {
|
|
6
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
7
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
8
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
9
|
-
}
|
|
10
6
|
try {
|
|
11
7
|
new globalThis.TextEncoderStream();
|
|
12
8
|
} catch {
|
|
@@ -8,11 +8,7 @@ import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-ha
|
|
|
8
8
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
|
-
export declare function createQwikRouter(opts: QwikRouterDenoOptions):
|
|
12
|
-
router: (request: Request, info: ServeHandlerInfo) => Promise<Response | null>;
|
|
13
|
-
notFound: (request: Request) => Promise<Response>;
|
|
14
|
-
staticFile: (request: Request) => Promise<Response | null>;
|
|
15
|
-
};
|
|
11
|
+
export declare function createQwikRouter(opts: QwikRouterDenoOptions): QwikRouterDenoMiddleware;
|
|
16
12
|
|
|
17
13
|
/** @public */
|
|
18
14
|
export declare interface NetAddr {
|
|
@@ -27,6 +23,14 @@ export declare interface NetAddr {
|
|
|
27
23
|
*/
|
|
28
24
|
export declare type QwikCityDenoOptions = QwikRouterDenoOptions;
|
|
29
25
|
|
|
26
|
+
/** @public */
|
|
27
|
+
export declare interface QwikRouterDenoMiddleware {
|
|
28
|
+
router: (request: Request, info: ServeHandlerInfo) => Promise<Response | null>;
|
|
29
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
30
|
+
notFound: (request: Request) => Promise<Response>;
|
|
31
|
+
staticFile: (request: Request) => Promise<Response | null>;
|
|
32
|
+
}
|
|
33
|
+
|
|
30
34
|
/** @public */
|
|
31
35
|
export declare interface QwikRouterDenoOptions extends ServerRenderOptions {
|
|
32
36
|
/** Options for serving static files */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
-
import { isStaticPath,
|
|
3
|
-
import { M as MIME_TYPES } from '../../chunks/
|
|
2
|
+
import { isStaticPath, mergeHeadersCookies, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
import { M as MIME_TYPES, n as normalizeRequestUrl } from '../../chunks/url.mjs';
|
|
4
4
|
import { join, fromFileUrl, extname } from 'https://deno.land/std/path/mod.ts';
|
|
5
5
|
import { isDev } from '@qwik.dev/core/build';
|
|
6
6
|
|
|
@@ -10,13 +10,9 @@ function getRequestUrl(request, opts, info) {
|
|
|
10
10
|
if (!origin) {
|
|
11
11
|
return url;
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return normalizeRequestUrl(`${url.pathname}${url.search}${url.hash}`, origin);
|
|
14
14
|
}
|
|
15
15
|
function createQwikRouter(opts) {
|
|
16
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
17
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
18
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
19
|
-
}
|
|
20
16
|
if (opts.manifest) {
|
|
21
17
|
setServerPlatform(opts.manifest);
|
|
22
18
|
}
|
|
@@ -73,27 +69,8 @@ function createQwikRouter(opts) {
|
|
|
73
69
|
});
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
|
-
const notFound = async (
|
|
77
|
-
|
|
78
|
-
const url = getRequestUrl(request, opts);
|
|
79
|
-
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
80
|
-
return new Response(notFoundHtml, {
|
|
81
|
-
status: 404,
|
|
82
|
-
headers: {
|
|
83
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
84
|
-
"X-Not-Found": url.pathname
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
} catch (e) {
|
|
88
|
-
console.error(e);
|
|
89
|
-
return new Response(isDev ? String(e || "Error") : "Internal Server Error", {
|
|
90
|
-
status: 500,
|
|
91
|
-
headers: {
|
|
92
|
-
"Content-Type": "text/plain; charset=utf-8",
|
|
93
|
-
"X-Error": "deno-server"
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
72
|
+
const notFound = async (_request) => {
|
|
73
|
+
return null;
|
|
97
74
|
};
|
|
98
75
|
const openStaticFile = async (url) => {
|
|
99
76
|
const pathname = url.pathname;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { createQwikRouter as createQwikRouter$1 } from '@qwik.dev/router/middleware/node';
|
|
2
2
|
|
|
3
3
|
function createQwikRouter(opts) {
|
|
4
|
-
|
|
5
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
6
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
7
|
-
}
|
|
8
|
-
const { staticFile, notFound, router } = createQwikRouter$1({
|
|
4
|
+
const { staticFile, router } = createQwikRouter$1({
|
|
9
5
|
render: opts.render,
|
|
10
6
|
manifest: opts.manifest,
|
|
11
|
-
qwikRouterConfig: opts.qwikRouterConfig,
|
|
12
7
|
static: {
|
|
13
8
|
cacheControl: "public, max-age=31557600"
|
|
14
9
|
},
|
|
@@ -21,8 +16,8 @@ function createQwikRouter(opts) {
|
|
|
21
16
|
});
|
|
22
17
|
const qwikApp = (req, res) => {
|
|
23
18
|
return staticFile(req, res, () => {
|
|
24
|
-
router(req, res, () =>
|
|
25
|
-
})
|
|
19
|
+
router(req, res, () => {
|
|
20
|
+
});
|
|
26
21
|
});
|
|
27
22
|
};
|
|
28
23
|
return qwikApp;
|
|
@@ -3,10 +3,6 @@ import { isStaticPath, mergeHeadersCookies, requestHandler, getNotFound } from '
|
|
|
3
3
|
import { isDev } from '@qwik.dev/core/build';
|
|
4
4
|
|
|
5
5
|
function createQwikRouter(opts) {
|
|
6
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
7
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
8
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
9
|
-
}
|
|
10
6
|
if (opts.manifest) {
|
|
11
7
|
setServerPlatform(opts.manifest);
|
|
12
8
|
}
|
|
@@ -11,11 +11,7 @@ import type { ServerResponse } from 'node:http';
|
|
|
11
11
|
export declare const createQwikCity: typeof createQwikRouter;
|
|
12
12
|
|
|
13
13
|
/** @public */
|
|
14
|
-
export declare function createQwikRouter(opts: QwikRouterNodeRequestOptions | QwikCityNodeRequestOptions):
|
|
15
|
-
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
16
|
-
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
17
|
-
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
18
|
-
};
|
|
14
|
+
export declare function createQwikRouter(opts: QwikRouterNodeRequestOptions | QwikCityNodeRequestOptions): QwikRouterNodeMiddleware;
|
|
19
15
|
|
|
20
16
|
/** @public */
|
|
21
17
|
export declare interface NodeRequestNextFunction {
|
|
@@ -35,6 +31,14 @@ export declare interface PlatformNode {
|
|
|
35
31
|
*/
|
|
36
32
|
export declare type QwikCityNodeRequestOptions = QwikRouterNodeRequestOptions;
|
|
37
33
|
|
|
34
|
+
/** @public */
|
|
35
|
+
export declare interface QwikRouterNodeMiddleware {
|
|
36
|
+
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: NodeRequestNextFunction) => Promise<void>;
|
|
37
|
+
/** @deprecated `router` handles 404 responses. Will be removed in V3. */
|
|
38
|
+
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e: any) => void) => Promise<void>;
|
|
39
|
+
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse, next: (e?: any) => void) => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
38
42
|
/** @public */
|
|
39
43
|
export declare interface QwikRouterNodeRequestOptions extends ServerRenderOptions {
|
|
40
44
|
/** Options for serving static files */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isDev } from '@qwik.dev/core';
|
|
2
2
|
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
3
|
-
import { isStaticPath,
|
|
3
|
+
import { isStaticPath, requestHandler } from '@qwik.dev/router/middleware/request-handler';
|
|
4
4
|
import { createReadStream } from 'node:fs';
|
|
5
5
|
import { join, basename, extname } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { M as MIME_TYPES } from '../../chunks/
|
|
7
|
+
import { n as normalizeRequestUrl, M as MIME_TYPES } from '../../chunks/url.mjs';
|
|
8
8
|
import { Http2ServerRequest } from 'node:http2';
|
|
9
9
|
|
|
10
10
|
function fallbackOrigin(req) {
|
|
@@ -27,8 +27,7 @@ function isIgnoredError(message = "") {
|
|
|
27
27
|
}
|
|
28
28
|
const invalidHeadersPattern = /^:(method|scheme|authority|path)$/i;
|
|
29
29
|
function normalizeUrl(url, base) {
|
|
30
|
-
|
|
31
|
-
return new URL(url.replace(DOUBLE_SLASH_REG, "/"), base);
|
|
30
|
+
return normalizeRequestUrl(url, base);
|
|
32
31
|
}
|
|
33
32
|
function getUrl(req, origin) {
|
|
34
33
|
return normalizeUrl(req.originalUrl || req.url || "/", origin);
|
|
@@ -126,10 +125,6 @@ async function fromNodeHttp(url, req, res, mode, getClientConn) {
|
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
function createQwikRouter(opts) {
|
|
129
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
130
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
131
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
132
|
-
}
|
|
133
128
|
if (opts.manifest) {
|
|
134
129
|
setServerPlatform(opts.manifest);
|
|
135
130
|
}
|
|
@@ -157,23 +152,7 @@ function createQwikRouter(opts) {
|
|
|
157
152
|
next(e);
|
|
158
153
|
}
|
|
159
154
|
};
|
|
160
|
-
const notFound = async (
|
|
161
|
-
try {
|
|
162
|
-
if (!res.headersSent) {
|
|
163
|
-
const origin = computeOrigin(req, opts);
|
|
164
|
-
const url = getUrl(req, origin);
|
|
165
|
-
const notFoundHtml = !req.headers.accept?.includes("text/html") || isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
166
|
-
res.writeHead(404, {
|
|
167
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
168
|
-
"X-Not-Found": url.pathname
|
|
169
|
-
});
|
|
170
|
-
res.end(notFoundHtml);
|
|
171
|
-
}
|
|
172
|
-
} catch (e) {
|
|
173
|
-
console.error(e);
|
|
174
|
-
next(e);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
155
|
+
const notFound = async (_req, _res, next) => next();
|
|
177
156
|
const staticFile = async (req, res, next) => {
|
|
178
157
|
try {
|
|
179
158
|
const origin = computeOrigin(req, opts);
|
|
@@ -4,9 +4,7 @@ import type { EnvGetter as EnvGetter_2 } from '@qwik.dev/router/middleware/reque
|
|
|
4
4
|
import type { FailReturn } from '@qwik.dev/router';
|
|
5
5
|
import type { JSXOutput } from '@qwik.dev/core';
|
|
6
6
|
import type { Loader as Loader_2 } from '@qwik.dev/router';
|
|
7
|
-
import type { QwikCityPlan } from '@qwik.dev/router';
|
|
8
7
|
import type { QwikIntrinsicElements } from '@qwik.dev/core';
|
|
9
|
-
import type { QwikRouterConfig } from '@qwik.dev/router';
|
|
10
8
|
import type { Render } from '@qwik.dev/core/server';
|
|
11
9
|
import type { RenderOptions } from '@qwik.dev/core/server';
|
|
12
10
|
import { RequestEvent as RequestEvent_2 } from '@qwik.dev/router/middleware/request-handler';
|
|
@@ -632,7 +630,10 @@ export declare type RequestHandler<PLATFORM = QwikRouterPlatform> = (ev: Request
|
|
|
632
630
|
export declare function requestHandler<T = unknown>(serverRequestEv: ServerRequestEvent<T>, opts: ServerRenderOptions): Promise<QwikRouterRun<T> | null>;
|
|
633
631
|
|
|
634
632
|
/** @public */
|
|
635
|
-
declare type ResolvedDocumentHead<FrontMatter extends Record<string, any> = Record<string, unknown>> = Required<DocumentHeadValue<FrontMatter
|
|
633
|
+
declare type ResolvedDocumentHead<FrontMatter extends Record<string, any> = Record<string, unknown>> = Required<DocumentHeadValue<FrontMatter>> & {
|
|
634
|
+
/** The build's manifest hash, used for per-loader data URLs. Always defined (`'dev'` in dev). */
|
|
635
|
+
readonly manifestHash: string;
|
|
636
|
+
};
|
|
636
637
|
|
|
637
638
|
/** @public */
|
|
638
639
|
export declare interface ResolveSyncValue {
|
|
@@ -715,10 +716,6 @@ declare type ServerErrorCode = 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 5
|
|
|
715
716
|
/** @public */
|
|
716
717
|
export declare interface ServerRenderOptions extends RenderOptions {
|
|
717
718
|
render: Render;
|
|
718
|
-
/** @deprecated Not used */
|
|
719
|
-
qwikCityPlan?: QwikCityPlan;
|
|
720
|
-
/** @deprecated Not used */
|
|
721
|
-
qwikRouterConfig?: QwikRouterConfig;
|
|
722
719
|
/**
|
|
723
720
|
* Protection against cross-site request forgery (CSRF) attacks.
|
|
724
721
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Q as Q_ROUTE, m as resolveRouteConfig, n as QLOADER_KEY, h as QFN_KEY, j as QACTION_KEY, o as isPromise, k as QDATA_KEY,
|
|
1
|
+
import { Q as Q_ROUTE, m as resolveRouteConfig, n as QLOADER_KEY, h as QFN_KEY, j as QACTION_KEY, o as isPromise, k as QDATA_KEY, b as loadRoute } from '../../chunks/routing.qwik.mjs';
|
|
2
2
|
import { isDev, _UNINITIALIZED, _deserialize, _verifySerializable, _serialize } from '@qwik.dev/core/internal';
|
|
3
3
|
import { inlinedQrl } from '@qwik.dev/core';
|
|
4
4
|
import { R as RedirectMessage, A as AbortMessage } from '../../chunks/redirect-handler.mjs';
|
|
@@ -647,7 +647,7 @@ function createResolveRequestHandlers(deps) {
|
|
|
647
647
|
const routeLoaders = [];
|
|
648
648
|
const routeActions = [];
|
|
649
649
|
const requestHandlers = [];
|
|
650
|
-
const isPageRoute = !!
|
|
650
|
+
const isPageRoute = !!isLastModulePageRoute(route.$mods$);
|
|
651
651
|
if (isInternal) {
|
|
652
652
|
requestHandlers.push(handleQDataRedirect);
|
|
653
653
|
}
|
|
@@ -657,36 +657,36 @@ function createResolveRequestHandlers(deps) {
|
|
|
657
657
|
if (serverPlugins) {
|
|
658
658
|
_resolveRequestHandlers(routeLoaders, routeActions, requestHandlers, serverPlugins, isPageRoute, method);
|
|
659
659
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
if (checkOrigin
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
requestHandlers.unshift(csrfCheckMiddleware);
|
|
669
|
-
}
|
|
660
|
+
const routeModules = route.$mods$;
|
|
661
|
+
_resolveRequestHandlers(routeLoaders, routeActions, requestHandlers, routeModules, isPageRoute, method);
|
|
662
|
+
const routeName = route.$routeName$;
|
|
663
|
+
if (checkOrigin && (method === "POST" || method === "PUT" || method === "PATCH" || method === "DELETE")) {
|
|
664
|
+
if (checkOrigin === "lax-proto") {
|
|
665
|
+
requestHandlers.unshift(csrfLaxProtoCheckMiddleware);
|
|
666
|
+
} else {
|
|
667
|
+
requestHandlers.unshift(csrfCheckMiddleware);
|
|
670
668
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
669
|
+
}
|
|
670
|
+
if (isPageRoute) {
|
|
671
|
+
if (method === "POST" || method === "GET") {
|
|
672
|
+
requestHandlers.push(runServerFunction);
|
|
673
|
+
}
|
|
674
|
+
if (!route.$notFound$) {
|
|
675
675
|
requestHandlers.push(fixTrailingSlash);
|
|
676
|
-
if (isInternal) {
|
|
677
|
-
requestHandlers.push(renderQData);
|
|
678
|
-
}
|
|
679
676
|
}
|
|
680
|
-
if (
|
|
681
|
-
requestHandlers.push(
|
|
682
|
-
ev.sharedMap.set(deps.RequestRouteName, routeName);
|
|
683
|
-
});
|
|
684
|
-
requestHandlers.push(actionsMiddleware(routeActions));
|
|
685
|
-
requestHandlers.push(loadersMiddleware(routeLoaders));
|
|
686
|
-
requestHandlers.push(eTagMiddleware(route));
|
|
687
|
-
requestHandlers.push(renderHandler);
|
|
677
|
+
if (isInternal) {
|
|
678
|
+
requestHandlers.push(renderQData);
|
|
688
679
|
}
|
|
689
680
|
}
|
|
681
|
+
if (isPageRoute) {
|
|
682
|
+
requestHandlers.push((ev) => {
|
|
683
|
+
ev.sharedMap.set(deps.RequestRouteName, routeName);
|
|
684
|
+
});
|
|
685
|
+
requestHandlers.push(actionsMiddleware(routeActions));
|
|
686
|
+
requestHandlers.push(loadersMiddleware(routeLoaders));
|
|
687
|
+
requestHandlers.push(eTagMiddleware(route));
|
|
688
|
+
requestHandlers.push(renderHandler);
|
|
689
|
+
}
|
|
690
690
|
return requestHandlers;
|
|
691
691
|
};
|
|
692
692
|
const _resolveRequestHandlers = (routeLoaders, routeActions, requestHandlers, routeModules, collectActions, method) => {
|
|
@@ -1632,9 +1632,15 @@ function runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRou
|
|
|
1632
1632
|
});
|
|
1633
1633
|
}
|
|
1634
1634
|
|
|
1635
|
-
let
|
|
1636
|
-
async function
|
|
1637
|
-
|
|
1635
|
+
let qwikRouterConfig;
|
|
1636
|
+
async function getConfig() {
|
|
1637
|
+
if (!qwikRouterConfig) {
|
|
1638
|
+
qwikRouterConfig = await import('@qwik-router-config');
|
|
1639
|
+
}
|
|
1640
|
+
return qwikRouterConfig;
|
|
1641
|
+
}
|
|
1642
|
+
async function loadRequestHandlers(qwikRouterConfig2, pathname, method, checkOrigin, renderFn, isInternal) {
|
|
1643
|
+
const { routes, serverPlugins, cacheModules } = qwikRouterConfig2;
|
|
1638
1644
|
const loadedRoute = await loadRoute(routes, cacheModules, pathname, isInternal);
|
|
1639
1645
|
const requestHandlers = resolveRequestHandlers(serverPlugins, loadedRoute, method, checkOrigin, renderQwikMiddleware(renderFn), isInternal);
|
|
1640
1646
|
return {
|
|
@@ -1644,29 +1650,20 @@ async function loadRequestHandlers(qwikRouterConfig, pathname, method, checkOrig
|
|
|
1644
1650
|
}
|
|
1645
1651
|
async function requestHandler(serverRequestEv, opts) {
|
|
1646
1652
|
const { render, checkOrigin } = opts;
|
|
1647
|
-
|
|
1648
|
-
if (!qwikRouterConfig) {
|
|
1649
|
-
if (!qwikRouterConfigActual) {
|
|
1650
|
-
qwikRouterConfigActual = await import('@qwik-router-config');
|
|
1651
|
-
}
|
|
1652
|
-
qwikRouterConfig = qwikRouterConfigActual;
|
|
1653
|
-
}
|
|
1654
|
-
if (!qwikRouterConfig) {
|
|
1655
|
-
throw new Error("qwikRouterConfig is required.");
|
|
1656
|
-
}
|
|
1653
|
+
const config = await getConfig();
|
|
1657
1654
|
const { pathname, isInternal } = getRouteMatchPathname(serverRequestEv.url.pathname);
|
|
1658
1655
|
if (pathname === "/.well-known" || pathname.startsWith("/.well-known/")) {
|
|
1659
1656
|
return null;
|
|
1660
1657
|
}
|
|
1661
|
-
const { loadedRoute, requestHandlers } = await loadRequestHandlers(
|
|
1662
|
-
if (
|
|
1658
|
+
const { loadedRoute, requestHandlers } = await loadRequestHandlers(config, pathname, serverRequestEv.request.method, checkOrigin ?? true, render, isInternal);
|
|
1659
|
+
if (config.fallthrough && loadedRoute.$notFound$) {
|
|
1663
1660
|
return null;
|
|
1664
1661
|
}
|
|
1665
1662
|
const rebuildRouteInfo = async (url) => {
|
|
1666
1663
|
const { pathname: pathname2 } = getRouteMatchPathname(url.pathname);
|
|
1667
|
-
return loadRequestHandlers(
|
|
1664
|
+
return loadRequestHandlers(config, pathname2, serverRequestEv.request.method, checkOrigin ?? true, render, isInternal);
|
|
1668
1665
|
};
|
|
1669
|
-
return runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo,
|
|
1666
|
+
return runQwikRouter(serverRequestEv, loadedRoute, requestHandlers, rebuildRouteInfo, config.basePathname);
|
|
1670
1667
|
}
|
|
1671
1668
|
|
|
1672
1669
|
const notFounds = [
|
|
@@ -9,10 +9,6 @@ const VERCEL_SKEW_PROTECTION_ENABLED = "VERCEL_SKEW_PROTECTION_ENABLED";
|
|
|
9
9
|
const VERCEL_DEPLOYMENT_ID = "VERCEL_DEPLOYMENT_ID";
|
|
10
10
|
const BASE_URL = "BASE_URL";
|
|
11
11
|
function createQwikRouter(opts) {
|
|
12
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
13
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
14
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
15
|
-
}
|
|
16
12
|
if (opts.manifest) {
|
|
17
13
|
setServerPlatform(opts.manifest);
|
|
18
14
|
}
|