@qwik.dev/router 2.0.0-beta.2 → 2.0.0-beta.21
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/adapters/static/vite.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.d.ts +2 -2
- package/lib/adapters/azure-swa/vite/index.mjs +9 -9
- package/lib/adapters/bun-server/vite/index.d.ts +2 -2
- package/lib/adapters/bun-server/vite/index.mjs +9 -7
- package/lib/adapters/cloud-run/vite/index.d.ts +2 -2
- package/lib/adapters/cloud-run/vite/index.mjs +9 -7
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +2 -2
- package/lib/adapters/cloudflare-pages/vite/index.mjs +9 -24
- package/lib/adapters/deno-server/vite/index.d.ts +2 -2
- package/lib/adapters/deno-server/vite/index.mjs +9 -7
- package/lib/adapters/netlify-edge/vite/index.d.ts +2 -2
- package/lib/adapters/netlify-edge/vite/index.mjs +10 -14
- package/lib/adapters/node-server/vite/index.d.ts +2 -2
- package/lib/adapters/node-server/vite/index.mjs +9 -7
- package/lib/adapters/shared/vite/index.d.ts +13 -19
- package/lib/adapters/shared/vite/index.mjs +107 -139
- package/lib/adapters/ssg/vite/index.d.ts +13 -0
- package/lib/adapters/ssg/vite/index.mjs +18 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +3 -3
- package/lib/adapters/vercel-edge/vite/index.mjs +9 -11
- package/lib/chunks/error-handler.mjs +57 -0
- package/lib/chunks/format-error.mjs +137 -0
- package/lib/chunks/fs.mjs +254 -0
- package/lib/{static/node.mjs → chunks/index.mjs} +361 -563
- package/lib/chunks/mime-types.mjs +52 -0
- package/lib/chunks/routing.qwik.mjs +429 -0
- package/lib/chunks/types.qwik.mjs +22 -0
- package/lib/index.d.ts +240 -60
- package/lib/index.qwik.mjs +698 -983
- package/lib/middleware/aws-lambda/index.d.ts +3 -2
- package/lib/middleware/aws-lambda/index.mjs +8 -12
- package/lib/middleware/azure-swa/index.mjs +10 -216
- package/lib/middleware/bun/index.d.ts +11 -0
- package/lib/middleware/bun/index.mjs +24 -83
- package/lib/middleware/cloudflare-pages/index.mjs +10 -22
- package/lib/middleware/deno/index.d.ts +11 -0
- package/lib/middleware/deno/index.mjs +24 -83
- package/lib/middleware/firebase/index.mjs +7 -11
- package/lib/middleware/netlify-edge/index.mjs +10 -23
- package/lib/middleware/node/index.mjs +22 -87
- package/lib/middleware/request-handler/index.d.ts +89 -70
- package/lib/middleware/request-handler/index.mjs +584 -659
- package/lib/middleware/vercel-edge/index.mjs +15 -27
- package/lib/modules.d.ts +4 -12
- package/lib/service-worker/index.mjs +4 -0
- package/lib/{static → ssg}/index.d.ts +17 -17
- package/lib/ssg/index.mjs +14 -0
- package/lib/vite/index.d.ts +32 -10
- package/lib/vite/index.mjs +1524 -26934
- package/modules.d.ts +4 -12
- package/package.json +62 -68
- package/ssg.d.ts +2 -0
- package/static.d.ts +1 -1
- package/lib/adapters/azure-swa/vite/index.cjs +0 -96
- package/lib/adapters/bun-server/vite/index.cjs +0 -50
- package/lib/adapters/cloud-run/vite/index.cjs +0 -47
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -115
- package/lib/adapters/deno-server/vite/index.cjs +0 -62
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -129
- package/lib/adapters/node-server/vite/index.cjs +0 -50
- package/lib/adapters/shared/vite/index.cjs +0 -378
- package/lib/adapters/static/vite/index.cjs +0 -368
- package/lib/adapters/static/vite/index.d.ts +0 -10
- package/lib/adapters/static/vite/index.mjs +0 -331
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -118
- package/lib/index.qwik.cjs +0 -1947
- package/lib/middleware/node/index.cjs +0 -314
- package/lib/middleware/request-handler/index.cjs +0 -1614
- package/lib/service-worker.cjs +0 -17
- package/lib/service-worker.mjs +0 -15
- package/lib/static/deno.mjs +0 -8
- package/lib/static/index.cjs +0 -67
- package/lib/static/index.mjs +0 -48
- package/lib/static/node.cjs +0 -1124
- package/lib/vite/index.cjs +0 -27445
- package/middleware/request-handler/generated/not-found-paths.ts +0 -7
- package/middleware/request-handler/generated/static-paths.ts +0 -35
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import { getNotFound } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var VERCEL_SKEW_PROTECTION_ENABLED = "VERCEL_SKEW_PROTECTION_ENABLED";
|
|
11
|
-
var VERCEL_DEPLOYMENT_ID = "VERCEL_DEPLOYMENT_ID";
|
|
12
|
-
var BASE_URL = "BASE_URL";
|
|
1
|
+
import { setServerPlatform } from '@qwik.dev/core/server';
|
|
2
|
+
import { isStaticPath, mergeHeadersCookies, requestHandler, getNotFound } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
|
|
4
|
+
const COUNTRY_HEADER_NAME = "x-vercel-ip-country";
|
|
5
|
+
const IP_HEADER_NAME = "x-real-ip";
|
|
6
|
+
const VERCEL_COOKIE = "__vdpl";
|
|
7
|
+
const VERCEL_SKEW_PROTECTION_ENABLED = "VERCEL_SKEW_PROTECTION_ENABLED";
|
|
8
|
+
const VERCEL_DEPLOYMENT_ID = "VERCEL_DEPLOYMENT_ID";
|
|
9
|
+
const BASE_URL = "BASE_URL";
|
|
13
10
|
function createQwikRouter(opts) {
|
|
14
11
|
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
15
|
-
console.warn("qwikCityPlan is deprecated.
|
|
12
|
+
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
16
13
|
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
17
|
-
} else if (!opts.qwikRouterConfig) {
|
|
18
|
-
throw new Error("qwikRouterConfig is required.");
|
|
19
14
|
}
|
|
20
|
-
const qwikSerializer = {
|
|
21
|
-
_deserialize,
|
|
22
|
-
_serialize,
|
|
23
|
-
_verifySerializable
|
|
24
|
-
};
|
|
25
15
|
if (opts.manifest) {
|
|
26
16
|
setServerPlatform(opts.manifest);
|
|
27
17
|
}
|
|
@@ -75,7 +65,7 @@ function createQwikRouter(opts) {
|
|
|
75
65
|
};
|
|
76
66
|
}
|
|
77
67
|
};
|
|
78
|
-
const handledResponse = await requestHandler(serverRequestEv, opts
|
|
68
|
+
const handledResponse = await requestHandler(serverRequestEv, opts);
|
|
79
69
|
if (handledResponse) {
|
|
80
70
|
handledResponse.completion.then((v) => {
|
|
81
71
|
if (v) {
|
|
@@ -87,7 +77,7 @@ function createQwikRouter(opts) {
|
|
|
87
77
|
return response;
|
|
88
78
|
}
|
|
89
79
|
}
|
|
90
|
-
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
80
|
+
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
91
81
|
return new Response(notFoundHtml, {
|
|
92
82
|
status: 404,
|
|
93
83
|
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
@@ -102,8 +92,6 @@ function createQwikRouter(opts) {
|
|
|
102
92
|
}
|
|
103
93
|
return onVercelEdgeRequest;
|
|
104
94
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
createQwikRouter
|
|
109
|
-
};
|
|
95
|
+
const createQwikCity = createQwikRouter;
|
|
96
|
+
|
|
97
|
+
export { createQwikCity, createQwikRouter };
|
package/lib/modules.d.ts
CHANGED
|
@@ -19,20 +19,12 @@ declare module '@qwik-city-plan' {
|
|
|
19
19
|
export { default } from '@qwik-router-config';
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
declare module '@qwik-router-not-found-paths' {
|
|
23
|
-
function getNotFound(_pathname: string): string;
|
|
24
|
-
export { getNotFound };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
declare module '@qwik-city-not-found-paths' {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
declare module '@qwik-router-static-paths' {
|
|
32
|
-
function isStaticPath(method: string, url: URL): boolean;
|
|
33
|
-
export { isStaticPath };
|
|
23
|
+
/** @deprecated Use `getNotFound` from `@qwik.dev/router/middleware/request-handler` instead. */
|
|
24
|
+
export { getNotFound } from '@qwik.dev/router/middleware/request-handler';
|
|
34
25
|
}
|
|
35
26
|
|
|
36
27
|
declare module '@qwik-city-static-paths' {
|
|
37
|
-
|
|
28
|
+
/** @deprecated Use `isStaticPath` from `@qwik.dev/router/middleware/request-handler` instead. */
|
|
29
|
+
export { isStaticPath } from '@qwik.dev/router/middleware/request-handler';
|
|
38
30
|
}
|
|
@@ -9,23 +9,7 @@ import type { RenderOptions } from '@qwik.dev/core/server';
|
|
|
9
9
|
export declare function generate(opts: StaticGenerateOptions): Promise<StaticGenerateResult>;
|
|
10
10
|
|
|
11
11
|
/** @public */
|
|
12
|
-
export declare interface
|
|
13
|
-
/**
|
|
14
|
-
* Path to the SSR module exporting the default render function. In most cases it'll be
|
|
15
|
-
* `./src/entry.ssr.tsx`.
|
|
16
|
-
*/
|
|
17
|
-
renderModulePath: string;
|
|
18
|
-
/** Path to the Qwik Router Config module exporting the default `@qwik-router-config`. */
|
|
19
|
-
qwikRouterConfigModulePath: string;
|
|
20
|
-
/** @deprecated Use `qwikRouterConfigModulePath` instead. Will be removed in V3 */
|
|
21
|
-
qwikCityPlanModulePath?: string;
|
|
22
|
-
/** Defaults to `/` */
|
|
23
|
-
basePathname?: string;
|
|
24
|
-
rootDir?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @public */
|
|
28
|
-
export declare interface StaticGenerateRenderOptions extends RenderOptions {
|
|
12
|
+
export declare interface SsgRenderOptions extends RenderOptions {
|
|
29
13
|
/** File system directory where the static files should be written. */
|
|
30
14
|
outDir: string;
|
|
31
15
|
/**
|
|
@@ -85,6 +69,22 @@ export declare interface StaticGenerateRenderOptions extends RenderOptions {
|
|
|
85
69
|
exclude?: string[];
|
|
86
70
|
}
|
|
87
71
|
|
|
72
|
+
/** @public */
|
|
73
|
+
export declare interface StaticGenerateOptions extends SsgRenderOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Path to the SSR module exporting the default render function. In most cases it'll be
|
|
76
|
+
* `./src/entry.ssr.tsx`.
|
|
77
|
+
*/
|
|
78
|
+
renderModulePath: string;
|
|
79
|
+
/** Path to the Qwik Router Config module exporting the default `@qwik-router-config`. */
|
|
80
|
+
qwikRouterConfigModulePath: string;
|
|
81
|
+
/** @deprecated Use `qwikRouterConfigModulePath` instead. Will be removed in V3 */
|
|
82
|
+
qwikCityPlanModulePath?: string;
|
|
83
|
+
/** Defaults to `/` */
|
|
84
|
+
basePathname?: string;
|
|
85
|
+
rootDir?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
88
|
/** @public */
|
|
89
89
|
export declare interface StaticGenerateResult {
|
|
90
90
|
duration: number;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
async function generate(opts) {
|
|
2
|
+
const ssgPlatform = await getEntryModule();
|
|
3
|
+
const result = await ssgPlatform.generate(opts);
|
|
4
|
+
return result;
|
|
5
|
+
}
|
|
6
|
+
async function getEntryModule() {
|
|
7
|
+
try {
|
|
8
|
+
return await import('../chunks/index.mjs');
|
|
9
|
+
} catch (e) {
|
|
10
|
+
throw new Error(`Unsupported platform`, { cause: e });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { generate };
|
package/lib/vite/index.d.ts
CHANGED
|
@@ -4,15 +4,16 @@ import type { Config } from 'svgo';
|
|
|
4
4
|
import { ConfigEnv } from 'vite';
|
|
5
5
|
import type { Plugin as Plugin_2 } from 'vite';
|
|
6
6
|
import type { PluginOption } from 'vite';
|
|
7
|
+
import type { SerializationStrategy } from '@qwik.dev/core/internal';
|
|
7
8
|
import { UserConfigExport } from 'vite';
|
|
8
9
|
|
|
9
|
-
declare interface
|
|
10
|
+
declare interface BuiltEntry extends ParsedPathname {
|
|
10
11
|
id: string;
|
|
11
12
|
chunkFileName: string;
|
|
12
13
|
filePath: string;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
declare interface
|
|
16
|
+
declare interface BuiltLayout {
|
|
16
17
|
filePath: string;
|
|
17
18
|
dirPath: string;
|
|
18
19
|
id: string;
|
|
@@ -20,7 +21,7 @@ declare interface BuildLayout {
|
|
|
20
21
|
layoutName: string;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
declare interface
|
|
24
|
+
declare interface BuiltRoute extends ParsedPathname {
|
|
24
25
|
/** Unique id built from its relative file system path */
|
|
25
26
|
id: string;
|
|
26
27
|
/** Local file system path */
|
|
@@ -28,7 +29,7 @@ declare interface BuildRoute extends ParsedPathname {
|
|
|
28
29
|
ext: string;
|
|
29
30
|
/** URL Pathname */
|
|
30
31
|
pathname: string;
|
|
31
|
-
layouts:
|
|
32
|
+
layouts: BuiltLayout[];
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
/** @public */
|
|
@@ -80,13 +81,13 @@ declare interface PathnameSegmentPart {
|
|
|
80
81
|
|
|
81
82
|
/** @public */
|
|
82
83
|
declare interface PluginOptions {
|
|
83
|
-
/** Directory of the `routes`. Defaults to `src/routes`. */
|
|
84
|
+
/** Directory of the `routes`. Defaults to `"src/routes"`. */
|
|
84
85
|
routesDir?: string;
|
|
85
|
-
/** Directory of the `server plugins`. Defaults to `
|
|
86
|
+
/** Directory of the `server plugins`. Defaults to `routesDir`. */
|
|
86
87
|
serverPluginsDir?: string;
|
|
87
88
|
/**
|
|
88
89
|
* The base pathname is used to create absolute URL paths up to the `hostname`, and must always
|
|
89
|
-
* start and end with a `/`. Defaults to
|
|
90
|
+
* start and end with a `/`. Defaults to `"/""`.
|
|
90
91
|
*/
|
|
91
92
|
basePathname?: string;
|
|
92
93
|
/**
|
|
@@ -98,10 +99,18 @@ declare interface PluginOptions {
|
|
|
98
99
|
mdxPlugins?: MdxPlugins;
|
|
99
100
|
/** MDX Options https://mdxjs.com/ */
|
|
100
101
|
mdx?: any;
|
|
101
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Extend the `platform` object in RequestEvent, which can be used to e.g. mock Cloudflare
|
|
104
|
+
* bindings.
|
|
105
|
+
*
|
|
106
|
+
* This only works in **dev mode** and only when using the in-process Vite dev server middleware
|
|
107
|
+
* (the default).
|
|
108
|
+
*/
|
|
102
109
|
platform?: Record<string, unknown>;
|
|
103
110
|
/** Configuration to rewrite url paths */
|
|
104
111
|
rewriteRoutes?: RewriteRouteOption[];
|
|
112
|
+
/** The serialization strategy for route loaders. Defaults to `never`. */
|
|
113
|
+
defaultLoadersSerializationStrategy?: SerializationStrategy;
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
/**
|
|
@@ -133,8 +142,8 @@ export declare interface QwikRouterPlugin extends P<QwikRouterPluginApi> {
|
|
|
133
142
|
/** @public */
|
|
134
143
|
declare interface QwikRouterPluginApi {
|
|
135
144
|
getBasePathname: () => string;
|
|
136
|
-
getRoutes: () =>
|
|
137
|
-
getServiceWorkers: () =>
|
|
145
|
+
getRoutes: () => BuiltRoute[];
|
|
146
|
+
getServiceWorkers: () => BuiltEntry[];
|
|
138
147
|
}
|
|
139
148
|
|
|
140
149
|
/** @public */
|
|
@@ -143,6 +152,19 @@ export declare interface QwikRouterVitePluginOptions extends Omit<PluginOptions,
|
|
|
143
152
|
mdx?: MdxOptions;
|
|
144
153
|
platform?: Record<string, unknown>;
|
|
145
154
|
imageOptimization?: ImageOptimizationOptions;
|
|
155
|
+
/** Whether to use static imports for route modules (layout and index files). Defaults to `false`. */
|
|
156
|
+
staticImportRoutes?: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Qwik is an SSR first framework. This means that Qwik requires either SSR or SSG. In Vite dev
|
|
159
|
+
* mode the dev SSR server is responsible for rendering and pausing the application on the
|
|
160
|
+
* server.
|
|
161
|
+
*
|
|
162
|
+
* Under normal circumstances this should be on, unless you have your own dev SSR server setup and
|
|
163
|
+
* wish to disable this one.
|
|
164
|
+
*
|
|
165
|
+
* Default: true
|
|
166
|
+
*/
|
|
167
|
+
devSsrServer?: boolean;
|
|
146
168
|
}
|
|
147
169
|
|
|
148
170
|
/** @public */
|