@qwik.dev/router 0.0.0 → 2.0.0-alpha.1
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/LICENSE +22 -0
- package/README.md +15 -0
- package/adapters/azure-swa/vite.d.ts +2 -0
- package/adapters/bun-server/vite.d.ts +2 -0
- package/adapters/cloud-run/vite.d.ts +2 -0
- package/adapters/cloudflare-pages/vite.d.ts +2 -0
- package/adapters/deno-server/vite.d.ts +2 -0
- package/adapters/netlify-edge/vite.d.ts +2 -0
- package/adapters/node-server/vite.d.ts +2 -0
- package/adapters/shared/vite.d.ts +2 -0
- package/adapters/static/vite.d.ts +2 -0
- package/adapters/vercel-edge/vite.d.ts +2 -0
- package/index.d.ts +2 -0
- package/lib/adapters/azure-swa/vite/index.cjs +96 -0
- package/lib/adapters/azure-swa/vite/index.d.ts +13 -0
- package/lib/adapters/azure-swa/vite/index.mjs +61 -0
- package/lib/adapters/bun-server/vite/index.cjs +50 -0
- package/lib/adapters/bun-server/vite/index.d.ts +14 -0
- package/lib/adapters/bun-server/vite/index.mjs +25 -0
- package/lib/adapters/cloud-run/vite/index.cjs +47 -0
- package/lib/adapters/cloud-run/vite/index.d.ts +13 -0
- package/lib/adapters/cloud-run/vite/index.mjs +22 -0
- package/lib/adapters/cloudflare-pages/vite/index.cjs +115 -0
- package/lib/adapters/cloudflare-pages/vite/index.d.ts +27 -0
- package/lib/adapters/cloudflare-pages/vite/index.mjs +80 -0
- package/lib/adapters/deno-server/vite/index.cjs +62 -0
- package/lib/adapters/deno-server/vite/index.d.ts +14 -0
- package/lib/adapters/deno-server/vite/index.mjs +37 -0
- package/lib/adapters/netlify-edge/vite/index.cjs +129 -0
- package/lib/adapters/netlify-edge/vite/index.d.ts +44 -0
- package/lib/adapters/netlify-edge/vite/index.mjs +92 -0
- package/lib/adapters/node-server/vite/index.cjs +50 -0
- package/lib/adapters/node-server/vite/index.d.ts +14 -0
- package/lib/adapters/node-server/vite/index.mjs +25 -0
- package/lib/adapters/shared/vite/index.cjs +371 -0
- package/lib/adapters/shared/vite/index.d.ts +114 -0
- package/lib/adapters/shared/vite/index.mjs +331 -0
- package/lib/adapters/static/vite/index.cjs +361 -0
- package/lib/adapters/static/vite/index.d.ts +10 -0
- package/lib/adapters/static/vite/index.mjs +324 -0
- package/lib/adapters/vercel-edge/vite/index.cjs +118 -0
- package/lib/adapters/vercel-edge/vite/index.d.ts +45 -0
- package/lib/adapters/vercel-edge/vite/index.mjs +83 -0
- package/lib/index.d.ts +803 -0
- package/lib/index.qwik.cjs +1876 -0
- package/lib/index.qwik.mjs +1857 -0
- package/lib/middleware/aws-lambda/index.d.ts +50 -0
- package/lib/middleware/aws-lambda/index.mjs +55 -0
- package/lib/middleware/azure-swa/index.d.ts +28 -0
- package/lib/middleware/azure-swa/index.mjs +297 -0
- package/lib/middleware/bun/index.d.ts +35 -0
- package/lib/middleware/bun/index.mjs +208 -0
- package/lib/middleware/cloudflare-pages/index.d.ts +35 -0
- package/lib/middleware/cloudflare-pages/index.mjs +107 -0
- package/lib/middleware/deno/index.d.ts +47 -0
- package/lib/middleware/deno/index.mjs +195 -0
- package/lib/middleware/firebase/index.d.ts +26 -0
- package/lib/middleware/firebase/index.mjs +36 -0
- package/lib/middleware/netlify-edge/index.d.ts +27 -0
- package/lib/middleware/netlify-edge/index.mjs +83 -0
- package/lib/middleware/node/index.cjs +314 -0
- package/lib/middleware/node/index.d.ts +66 -0
- package/lib/middleware/node/index.mjs +287 -0
- package/lib/middleware/request-handler/index.cjs +1544 -0
- package/lib/middleware/request-handler/index.d.ts +681 -0
- package/lib/middleware/request-handler/index.mjs +1501 -0
- package/lib/middleware/vercel-edge/index.d.ts +26 -0
- package/lib/middleware/vercel-edge/index.mjs +109 -0
- package/lib/modules.d.ts +38 -0
- package/lib/service-worker.cjs +267 -0
- package/lib/service-worker.d.ts +4 -0
- package/lib/service-worker.mjs +265 -0
- package/lib/static/deno.mjs +8 -0
- package/lib/static/index.cjs +67 -0
- package/lib/static/index.d.ts +98 -0
- package/lib/static/index.mjs +48 -0
- package/lib/static/node.cjs +1124 -0
- package/lib/static/node.mjs +1086 -0
- package/lib/vite/index.cjs +27496 -0
- package/lib/vite/index.d.ts +154 -0
- package/lib/vite/index.mjs +27484 -0
- package/middleware/aws-lambda.d.ts +2 -0
- package/middleware/azure-swa.d.ts +2 -0
- package/middleware/bun.d.ts +2 -0
- package/middleware/cloudflare-pages.d.ts +2 -0
- package/middleware/deno.d.ts +2 -0
- package/middleware/firebase.d.ts +2 -0
- package/middleware/netlify-edge.d.ts +2 -0
- package/middleware/node.d.ts +2 -0
- package/middleware/request-handler/generated/not-found-paths.ts +7 -0
- package/middleware/request-handler/generated/static-paths.ts +35 -0
- package/middleware/request-handler.d.ts +2 -0
- package/middleware/vercel-edge.d.ts +2 -0
- package/modules.d.ts +38 -0
- package/package.json +171 -165
- package/service-worker.d.ts +2 -0
- package/static.d.ts +2 -0
- package/vite.d.ts +2 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
|
|
3
|
+
import { Http2ServerRequest } from 'http2';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import { NodeRequestNextFunction } from '@qwik.dev/router/middleware/node';
|
|
6
|
+
import type { QwikCityPlan } from '@qwik.dev/router';
|
|
7
|
+
import type { QwikManifest } from '@qwik.dev/core/optimizer';
|
|
8
|
+
import type { QwikRouterConfig } from '@qwik.dev/router';
|
|
9
|
+
import type { Render } from '@qwik.dev/core/server';
|
|
10
|
+
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
11
|
+
import { ServerResponse } from 'http';
|
|
12
|
+
|
|
13
|
+
declare interface AwsOpt {
|
|
14
|
+
render: Render;
|
|
15
|
+
manifest: QwikManifest;
|
|
16
|
+
qwikRouterConfig: QwikRouterConfig;
|
|
17
|
+
/** @deprecated Use `QwikRouterConfig` instead. Will be removed in V3 */
|
|
18
|
+
qwikCityPlan?: QwikCityPlan;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare const createQwikCity: typeof createQwikRouter;
|
|
26
|
+
|
|
27
|
+
/** @public */
|
|
28
|
+
export declare function createQwikRouter(opts: AwsOpt): {
|
|
29
|
+
fixPath: (pathT: string) => string;
|
|
30
|
+
router: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse<IncomingMessage>, next: NodeRequestNextFunction) => Promise<void>;
|
|
31
|
+
staticFile: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse<IncomingMessage>, next: (e?: any) => void) => Promise<void>;
|
|
32
|
+
notFound: (req: IncomingMessage | Http2ServerRequest, res: ServerResponse<IncomingMessage>, next: (e: any) => void) => Promise<void>;
|
|
33
|
+
handle: (req: any, res: any) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** @public */
|
|
37
|
+
export declare interface PlatformAwsLambda extends Object {
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use `QwikRouterAwsLambdaOptions` instead. Will be removed in V3
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export declare type QwikCityAwsLambdaOptions = QwikRouterAwsLambdaOptions;
|
|
45
|
+
|
|
46
|
+
/** @public */
|
|
47
|
+
export declare interface QwikRouterAwsLambdaOptions extends ServerRenderOptions {
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { }
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// packages/qwik-router/src/middleware/aws-lambda/index.ts
|
|
2
|
+
import { createQwikRouter as createQwikRouterNode } from "@qwik.dev/router/middleware/node";
|
|
3
|
+
function createQwikRouter(opts) {
|
|
4
|
+
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
5
|
+
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
6
|
+
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
7
|
+
} else if (!opts.qwikRouterConfig) {
|
|
8
|
+
throw new Error("qwikRouterConfig is required.");
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const { router, staticFile, notFound } = createQwikRouterNode({
|
|
12
|
+
render: opts.render,
|
|
13
|
+
qwikRouterConfig: opts.qwikRouterConfig,
|
|
14
|
+
manifest: opts.manifest,
|
|
15
|
+
static: {
|
|
16
|
+
cacheControl: "public, max-age=31557600"
|
|
17
|
+
},
|
|
18
|
+
getOrigin(req) {
|
|
19
|
+
if (process.env.IS_OFFLINE) {
|
|
20
|
+
return `http://${req.headers.host}`;
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const fixPath = (pathT) => {
|
|
26
|
+
if (opts.qwikRouterConfig.trailingSlash) {
|
|
27
|
+
const url = new URL(pathT, "http://aws-qwik.local");
|
|
28
|
+
if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
|
|
29
|
+
return pathT;
|
|
30
|
+
}
|
|
31
|
+
if (!url.pathname.endsWith("/")) {
|
|
32
|
+
return url.pathname + "/" + url.search;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return pathT;
|
|
36
|
+
};
|
|
37
|
+
const handle = (req, res) => {
|
|
38
|
+
req.url = fixPath(req.url);
|
|
39
|
+
staticFile(req, res, () => {
|
|
40
|
+
router(req, res, () => {
|
|
41
|
+
notFound(req, res, () => {
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
return { fixPath, router, staticFile, notFound, handle };
|
|
47
|
+
} catch (err) {
|
|
48
|
+
throw new Error(err.message);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
var createQwikCity = createQwikRouter;
|
|
52
|
+
export {
|
|
53
|
+
createQwikCity,
|
|
54
|
+
createQwikRouter
|
|
55
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AzureFunction } from '@azure/functions';
|
|
2
|
+
import type { Context } from '@azure/functions';
|
|
3
|
+
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare const createQwikCity: typeof createQwikRouter;
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export declare function createQwikRouter(opts: QwikRouterAzureOptions): AzureFunction;
|
|
13
|
+
|
|
14
|
+
/** @public */
|
|
15
|
+
export declare interface PlatformAzure extends Partial<Context> {
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `QwikRouterAzureOptions` instead. Will be removed in V3
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare type QwikCityAzureOptions = QwikRouterAzureOptions;
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export declare interface QwikRouterAzureOptions extends ServerRenderOptions {
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { }
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// node_modules/.pnpm/set-cookie-parser@2.6.0/node_modules/set-cookie-parser/lib/set-cookie.js
|
|
28
|
+
var require_set_cookie = __commonJS({
|
|
29
|
+
"node_modules/.pnpm/set-cookie-parser@2.6.0/node_modules/set-cookie-parser/lib/set-cookie.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
var defaultParseOptions = {
|
|
32
|
+
decodeValues: true,
|
|
33
|
+
map: false,
|
|
34
|
+
silent: false
|
|
35
|
+
};
|
|
36
|
+
function isNonEmptyString(str) {
|
|
37
|
+
return typeof str === "string" && !!str.trim();
|
|
38
|
+
}
|
|
39
|
+
function parseString2(setCookieValue, options) {
|
|
40
|
+
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
41
|
+
var nameValuePairStr = parts.shift();
|
|
42
|
+
var parsed = parseNameValuePair(nameValuePairStr);
|
|
43
|
+
var name = parsed.name;
|
|
44
|
+
var value = parsed.value;
|
|
45
|
+
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
46
|
+
try {
|
|
47
|
+
value = options.decodeValues ? decodeURIComponent(value) : value;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.error(
|
|
50
|
+
"set-cookie-parser encountered an error while decoding a cookie with value '" + value + "'. Set options.decodeValues to false to disable this feature.",
|
|
51
|
+
e
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
var cookie = {
|
|
55
|
+
name,
|
|
56
|
+
value
|
|
57
|
+
};
|
|
58
|
+
parts.forEach(function(part) {
|
|
59
|
+
var sides = part.split("=");
|
|
60
|
+
var key = sides.shift().trimLeft().toLowerCase();
|
|
61
|
+
var value2 = sides.join("=");
|
|
62
|
+
if (key === "expires") {
|
|
63
|
+
cookie.expires = new Date(value2);
|
|
64
|
+
} else if (key === "max-age") {
|
|
65
|
+
cookie.maxAge = parseInt(value2, 10);
|
|
66
|
+
} else if (key === "secure") {
|
|
67
|
+
cookie.secure = true;
|
|
68
|
+
} else if (key === "httponly") {
|
|
69
|
+
cookie.httpOnly = true;
|
|
70
|
+
} else if (key === "samesite") {
|
|
71
|
+
cookie.sameSite = value2;
|
|
72
|
+
} else {
|
|
73
|
+
cookie[key] = value2;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return cookie;
|
|
77
|
+
}
|
|
78
|
+
function parseNameValuePair(nameValuePairStr) {
|
|
79
|
+
var name = "";
|
|
80
|
+
var value = "";
|
|
81
|
+
var nameValueArr = nameValuePairStr.split("=");
|
|
82
|
+
if (nameValueArr.length > 1) {
|
|
83
|
+
name = nameValueArr.shift();
|
|
84
|
+
value = nameValueArr.join("=");
|
|
85
|
+
} else {
|
|
86
|
+
value = nameValuePairStr;
|
|
87
|
+
}
|
|
88
|
+
return { name, value };
|
|
89
|
+
}
|
|
90
|
+
function parse(input, options) {
|
|
91
|
+
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
92
|
+
if (!input) {
|
|
93
|
+
if (!options.map) {
|
|
94
|
+
return [];
|
|
95
|
+
} else {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (input.headers) {
|
|
100
|
+
if (typeof input.headers.getSetCookie === "function") {
|
|
101
|
+
input = input.headers.getSetCookie();
|
|
102
|
+
} else if (input.headers["set-cookie"]) {
|
|
103
|
+
input = input.headers["set-cookie"];
|
|
104
|
+
} else {
|
|
105
|
+
var sch = input.headers[Object.keys(input.headers).find(function(key) {
|
|
106
|
+
return key.toLowerCase() === "set-cookie";
|
|
107
|
+
})];
|
|
108
|
+
if (!sch && input.headers.cookie && !options.silent) {
|
|
109
|
+
console.warn(
|
|
110
|
+
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
input = sch;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!Array.isArray(input)) {
|
|
117
|
+
input = [input];
|
|
118
|
+
}
|
|
119
|
+
options = options ? Object.assign({}, defaultParseOptions, options) : defaultParseOptions;
|
|
120
|
+
if (!options.map) {
|
|
121
|
+
return input.filter(isNonEmptyString).map(function(str) {
|
|
122
|
+
return parseString2(str, options);
|
|
123
|
+
});
|
|
124
|
+
} else {
|
|
125
|
+
var cookies = {};
|
|
126
|
+
return input.filter(isNonEmptyString).reduce(function(cookies2, str) {
|
|
127
|
+
var cookie = parseString2(str, options);
|
|
128
|
+
cookies2[cookie.name] = cookie;
|
|
129
|
+
return cookies2;
|
|
130
|
+
}, cookies);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function splitCookiesString(cookiesString) {
|
|
134
|
+
if (Array.isArray(cookiesString)) {
|
|
135
|
+
return cookiesString;
|
|
136
|
+
}
|
|
137
|
+
if (typeof cookiesString !== "string") {
|
|
138
|
+
return [];
|
|
139
|
+
}
|
|
140
|
+
var cookiesStrings = [];
|
|
141
|
+
var pos = 0;
|
|
142
|
+
var start;
|
|
143
|
+
var ch;
|
|
144
|
+
var lastComma;
|
|
145
|
+
var nextStart;
|
|
146
|
+
var cookiesSeparatorFound;
|
|
147
|
+
function skipWhitespace() {
|
|
148
|
+
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
149
|
+
pos += 1;
|
|
150
|
+
}
|
|
151
|
+
return pos < cookiesString.length;
|
|
152
|
+
}
|
|
153
|
+
function notSpecialChar() {
|
|
154
|
+
ch = cookiesString.charAt(pos);
|
|
155
|
+
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
156
|
+
}
|
|
157
|
+
while (pos < cookiesString.length) {
|
|
158
|
+
start = pos;
|
|
159
|
+
cookiesSeparatorFound = false;
|
|
160
|
+
while (skipWhitespace()) {
|
|
161
|
+
ch = cookiesString.charAt(pos);
|
|
162
|
+
if (ch === ",") {
|
|
163
|
+
lastComma = pos;
|
|
164
|
+
pos += 1;
|
|
165
|
+
skipWhitespace();
|
|
166
|
+
nextStart = pos;
|
|
167
|
+
while (pos < cookiesString.length && notSpecialChar()) {
|
|
168
|
+
pos += 1;
|
|
169
|
+
}
|
|
170
|
+
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
171
|
+
cookiesSeparatorFound = true;
|
|
172
|
+
pos = nextStart;
|
|
173
|
+
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
174
|
+
start = pos;
|
|
175
|
+
} else {
|
|
176
|
+
pos = lastComma + 1;
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
pos += 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
183
|
+
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return cookiesStrings;
|
|
187
|
+
}
|
|
188
|
+
module.exports = parse;
|
|
189
|
+
module.exports.parse = parse;
|
|
190
|
+
module.exports.parseString = parseString2;
|
|
191
|
+
module.exports.splitCookiesString = splitCookiesString;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// packages/qwik-router/src/middleware/azure-swa/index.ts
|
|
196
|
+
var import_set_cookie_parser = __toESM(require_set_cookie(), 1);
|
|
197
|
+
import { getNotFound } from "@qwik-router-not-found-paths";
|
|
198
|
+
import { isStaticPath } from "@qwik-router-static-paths";
|
|
199
|
+
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
200
|
+
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
201
|
+
import { requestHandler } from "../request-handler/index.mjs";
|
|
202
|
+
function createQwikRouter(opts) {
|
|
203
|
+
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
204
|
+
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
205
|
+
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
206
|
+
} else if (!opts.qwikRouterConfig) {
|
|
207
|
+
throw new Error("qwikRouterConfig is required.");
|
|
208
|
+
}
|
|
209
|
+
const qwikSerializer = {
|
|
210
|
+
_deserialize,
|
|
211
|
+
_serialize,
|
|
212
|
+
_verifySerializable
|
|
213
|
+
};
|
|
214
|
+
if (opts.manifest) {
|
|
215
|
+
setServerPlatform(opts.manifest);
|
|
216
|
+
}
|
|
217
|
+
async function onAzureSwaRequest(context, req) {
|
|
218
|
+
try {
|
|
219
|
+
const url = new URL(req.headers["x-ms-original-url"]);
|
|
220
|
+
const options = {
|
|
221
|
+
method: req.method || "GET",
|
|
222
|
+
headers: req.headers,
|
|
223
|
+
body: req.bufferBody || req.rawBody || req.body
|
|
224
|
+
};
|
|
225
|
+
const serverRequestEv = {
|
|
226
|
+
mode: "server",
|
|
227
|
+
locale: void 0,
|
|
228
|
+
url,
|
|
229
|
+
platform: context,
|
|
230
|
+
env: {
|
|
231
|
+
get(key) {
|
|
232
|
+
return process.env[key];
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
request: new Request(url, options),
|
|
236
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
237
|
+
const response = {
|
|
238
|
+
status,
|
|
239
|
+
body: new Uint8Array(),
|
|
240
|
+
headers: {},
|
|
241
|
+
cookies: cookies.headers().map((header) => (0, import_set_cookie_parser.parseString)(header))
|
|
242
|
+
};
|
|
243
|
+
headers.forEach((value, key) => response.headers[key] = value);
|
|
244
|
+
return new WritableStream({
|
|
245
|
+
write(chunk) {
|
|
246
|
+
if (response.body instanceof Uint8Array) {
|
|
247
|
+
const newBuffer = new Uint8Array(response.body.length + chunk.length);
|
|
248
|
+
newBuffer.set(response.body);
|
|
249
|
+
newBuffer.set(chunk, response.body.length);
|
|
250
|
+
response.body = newBuffer;
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
close() {
|
|
254
|
+
resolve(response);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
},
|
|
258
|
+
getClientConn: () => {
|
|
259
|
+
return {
|
|
260
|
+
ip: req.headers["x-forwarded-client-Ip"],
|
|
261
|
+
country: void 0
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
|
|
266
|
+
if (handledResponse) {
|
|
267
|
+
handledResponse.completion.then((err) => {
|
|
268
|
+
if (err) {
|
|
269
|
+
console.error(err);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
const response = await handledResponse.response;
|
|
273
|
+
if (response) {
|
|
274
|
+
return response;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const notFoundHtml = isStaticPath(req.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
278
|
+
return {
|
|
279
|
+
status: 404,
|
|
280
|
+
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname },
|
|
281
|
+
body: notFoundHtml
|
|
282
|
+
};
|
|
283
|
+
} catch (e) {
|
|
284
|
+
console.error(e);
|
|
285
|
+
return {
|
|
286
|
+
status: 500,
|
|
287
|
+
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return onAzureSwaRequest;
|
|
292
|
+
}
|
|
293
|
+
var createQwikCity = createQwikRouter;
|
|
294
|
+
export {
|
|
295
|
+
createQwikCity,
|
|
296
|
+
createQwikRouter
|
|
297
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ClientConn } from '@qwik.dev/router/middleware/request-handler';
|
|
2
|
+
import type { ServerRenderOptions } from '@qwik.dev/router/middleware/request-handler';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `createQwikRouter` instead. Will be removed in V3
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare const createQwikCity: typeof createQwikRouter;
|
|
9
|
+
|
|
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
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use `QwikRouterBunOptions` instead. Will be removed in V3
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare type QwikCityBunOptions = QwikRouterBunOptions;
|
|
22
|
+
|
|
23
|
+
/** @public */
|
|
24
|
+
export declare interface QwikRouterBunOptions extends ServerRenderOptions {
|
|
25
|
+
/** Options for serving static files */
|
|
26
|
+
static?: {
|
|
27
|
+
/** The root folder for statics files. Defaults to /dist */
|
|
28
|
+
root?: string;
|
|
29
|
+
/** Set the Cache-Control header for all static files */
|
|
30
|
+
cacheControl?: string;
|
|
31
|
+
};
|
|
32
|
+
getClientConn?: (request: Request) => ClientConn;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { }
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// packages/qwik-router/src/middleware/bun/index.ts
|
|
2
|
+
import { getNotFound } from "@qwik-router-not-found-paths";
|
|
3
|
+
import { isStaticPath } from "@qwik-router-static-paths";
|
|
4
|
+
import { _deserialize, _serialize, _verifySerializable } from "@qwik.dev/core/internal";
|
|
5
|
+
import { setServerPlatform } from "@qwik.dev/core/server";
|
|
6
|
+
import {
|
|
7
|
+
_TextEncoderStream_polyfill,
|
|
8
|
+
mergeHeadersCookies,
|
|
9
|
+
requestHandler
|
|
10
|
+
} from "../request-handler/index.mjs";
|
|
11
|
+
import { extname, join } from "node:path";
|
|
12
|
+
|
|
13
|
+
// packages/qwik-router/src/middleware/request-handler/mime-types.ts
|
|
14
|
+
var MIME_TYPES = {
|
|
15
|
+
"3gp": "video/3gpp",
|
|
16
|
+
"3gpp": "video/3gpp",
|
|
17
|
+
asf: "video/x-ms-asf",
|
|
18
|
+
asx: "video/x-ms-asf",
|
|
19
|
+
avi: "video/x-msvideo",
|
|
20
|
+
avif: "image/avif",
|
|
21
|
+
bmp: "image/x-ms-bmp",
|
|
22
|
+
css: "text/css",
|
|
23
|
+
flv: "video/x-flv",
|
|
24
|
+
gif: "image/gif",
|
|
25
|
+
htm: "text/html",
|
|
26
|
+
html: "text/html",
|
|
27
|
+
ico: "image/x-icon",
|
|
28
|
+
jng: "image/x-jng",
|
|
29
|
+
jpeg: "image/jpeg",
|
|
30
|
+
jpg: "image/jpeg",
|
|
31
|
+
js: "application/javascript",
|
|
32
|
+
json: "application/json",
|
|
33
|
+
kar: "audio/midi",
|
|
34
|
+
m4a: "audio/x-m4a",
|
|
35
|
+
m4v: "video/x-m4v",
|
|
36
|
+
mid: "audio/midi",
|
|
37
|
+
midi: "audio/midi",
|
|
38
|
+
mng: "video/x-mng",
|
|
39
|
+
mov: "video/quicktime",
|
|
40
|
+
mp3: "audio/mpeg",
|
|
41
|
+
mp4: "video/mp4",
|
|
42
|
+
mpeg: "video/mpeg",
|
|
43
|
+
mpg: "video/mpeg",
|
|
44
|
+
ogg: "audio/ogg",
|
|
45
|
+
pdf: "application/pdf",
|
|
46
|
+
png: "image/png",
|
|
47
|
+
rar: "application/x-rar-compressed",
|
|
48
|
+
shtml: "text/html",
|
|
49
|
+
svg: "image/svg+xml",
|
|
50
|
+
svgz: "image/svg+xml",
|
|
51
|
+
tif: "image/tiff",
|
|
52
|
+
tiff: "image/tiff",
|
|
53
|
+
ts: "video/mp2t",
|
|
54
|
+
txt: "text/plain",
|
|
55
|
+
wbmp: "image/vnd.wap.wbmp",
|
|
56
|
+
webm: "video/webm",
|
|
57
|
+
webp: "image/webp",
|
|
58
|
+
wmv: "video/x-ms-wmv",
|
|
59
|
+
woff: "font/woff",
|
|
60
|
+
woff2: "font/woff2",
|
|
61
|
+
xml: "text/xml",
|
|
62
|
+
zip: "application/zip"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// packages/qwik-router/src/middleware/bun/index.ts
|
|
66
|
+
function createQwikRouter(opts) {
|
|
67
|
+
var _a;
|
|
68
|
+
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
69
|
+
console.warn("qwikCityPlan is deprecated. Use qwikRouterConfig instead.");
|
|
70
|
+
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
71
|
+
} else if (!opts.qwikRouterConfig) {
|
|
72
|
+
throw new Error("qwikRouterConfig is required.");
|
|
73
|
+
}
|
|
74
|
+
globalThis.TextEncoderStream ||= _TextEncoderStream_polyfill;
|
|
75
|
+
const qwikSerializer = { _deserialize, _serialize, _verifySerializable };
|
|
76
|
+
if (opts.manifest) {
|
|
77
|
+
setServerPlatform(opts.manifest);
|
|
78
|
+
}
|
|
79
|
+
const staticFolder = ((_a = opts.static) == null ? void 0 : _a.root) ?? join(Bun.fileURLToPath(import.meta.url), "..", "..", "dist");
|
|
80
|
+
async function router(request) {
|
|
81
|
+
try {
|
|
82
|
+
const url = new URL(request.url);
|
|
83
|
+
const serverRequestEv = {
|
|
84
|
+
mode: "server",
|
|
85
|
+
locale: void 0,
|
|
86
|
+
url,
|
|
87
|
+
env: {
|
|
88
|
+
get(key) {
|
|
89
|
+
return Bun.env[key];
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
request,
|
|
93
|
+
getWritableStream: (status, headers, cookies, resolve) => {
|
|
94
|
+
const { readable, writable } = new TransformStream();
|
|
95
|
+
const response = new Response(readable, {
|
|
96
|
+
status,
|
|
97
|
+
headers: mergeHeadersCookies(headers, cookies)
|
|
98
|
+
});
|
|
99
|
+
resolve(response);
|
|
100
|
+
return writable;
|
|
101
|
+
},
|
|
102
|
+
platform: {
|
|
103
|
+
ssr: true
|
|
104
|
+
},
|
|
105
|
+
getClientConn: () => {
|
|
106
|
+
return opts.getClientConn ? opts.getClientConn(request) : {};
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const handledResponse = await requestHandler(serverRequestEv, opts, qwikSerializer);
|
|
110
|
+
if (handledResponse) {
|
|
111
|
+
handledResponse.completion.then((v) => {
|
|
112
|
+
if (v) {
|
|
113
|
+
console.error(v);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
const response = await handledResponse.response;
|
|
117
|
+
if (response) {
|
|
118
|
+
const status = response.status;
|
|
119
|
+
const location = response.headers.get("Location");
|
|
120
|
+
const isRedirect = status >= 301 && status <= 308 && location;
|
|
121
|
+
if (isRedirect) {
|
|
122
|
+
return new Response(null, response);
|
|
123
|
+
}
|
|
124
|
+
return response;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.error(e);
|
|
130
|
+
return new Response(String(e || "Error"), {
|
|
131
|
+
status: 500,
|
|
132
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const notFound = async (request) => {
|
|
137
|
+
try {
|
|
138
|
+
const url = new URL(request.url);
|
|
139
|
+
const notFoundHtml = isStaticPath(request.method || "GET", url) ? "Not Found" : getNotFound(url.pathname);
|
|
140
|
+
return new Response(notFoundHtml, {
|
|
141
|
+
status: 404,
|
|
142
|
+
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
143
|
+
});
|
|
144
|
+
} catch (e) {
|
|
145
|
+
console.error(e);
|
|
146
|
+
return new Response(String(e || "Error"), {
|
|
147
|
+
status: 500,
|
|
148
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const openStaticFile = async (url) => {
|
|
153
|
+
const pathname = url.pathname;
|
|
154
|
+
const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
|
|
155
|
+
let filePath;
|
|
156
|
+
if (fileName.includes(".")) {
|
|
157
|
+
filePath = join(staticFolder, pathname);
|
|
158
|
+
} else if (opts.qwikRouterConfig.trailingSlash) {
|
|
159
|
+
filePath = join(staticFolder, pathname + "index.html");
|
|
160
|
+
} else {
|
|
161
|
+
filePath = join(staticFolder, pathname, "index.html");
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
filePath,
|
|
165
|
+
content: Bun.file(filePath)
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const staticFile = async (request) => {
|
|
169
|
+
var _a2;
|
|
170
|
+
try {
|
|
171
|
+
const url = new URL(request.url);
|
|
172
|
+
if (isStaticPath(request.method || "GET", url)) {
|
|
173
|
+
const { filePath, content } = await openStaticFile(url);
|
|
174
|
+
if (!await content.exists()) {
|
|
175
|
+
return new Response("Not Found", {
|
|
176
|
+
status: 404,
|
|
177
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Not-Found": url.pathname }
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
const ext = extname(filePath).replace(/^\./, "");
|
|
181
|
+
return new Response(await content.stream(), {
|
|
182
|
+
status: 200,
|
|
183
|
+
headers: {
|
|
184
|
+
"content-type": MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
185
|
+
"Cache-Control": ((_a2 = opts.static) == null ? void 0 : _a2.cacheControl) || "max-age=3600"
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
} catch (e) {
|
|
191
|
+
console.error(e);
|
|
192
|
+
return new Response(String(e || "Error"), {
|
|
193
|
+
status: 500,
|
|
194
|
+
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
router,
|
|
200
|
+
notFound,
|
|
201
|
+
staticFile
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
var createQwikCity = createQwikRouter;
|
|
205
|
+
export {
|
|
206
|
+
createQwikCity,
|
|
207
|
+
createQwikRouter
|
|
208
|
+
};
|