@qwik.dev/router 2.0.0-beta.13 → 2.0.0-beta.14
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/adapters/azure-swa/vite/index.mjs +7 -7
- package/lib/adapters/bun-server/vite/index.mjs +7 -7
- package/lib/adapters/cloud-run/vite/index.mjs +7 -7
- package/lib/adapters/cloudflare-pages/vite/index.mjs +8 -8
- package/lib/adapters/deno-server/vite/index.mjs +7 -7
- package/lib/adapters/netlify-edge/vite/index.mjs +7 -7
- package/lib/adapters/node-server/vite/index.mjs +7 -7
- package/lib/adapters/shared/vite/index.mjs +8 -8
- package/lib/adapters/ssg/vite/index.mjs +7 -8
- package/lib/adapters/vercel-edge/vite/index.mjs +7 -7
- package/lib/chunks/error-handler.mjs +2 -4
- package/lib/chunks/format-error.mjs +6 -6
- package/lib/chunks/fs.mjs +6 -27
- package/lib/chunks/index.mjs +39 -31
- package/lib/chunks/mime-types.mjs +2 -3
- package/lib/chunks/routing.qwik.mjs +23 -47
- package/lib/chunks/types.qwik.mjs +2 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.qwik.mjs +48 -68
- package/lib/middleware/aws-lambda/index.mjs +4 -5
- package/lib/middleware/azure-swa/index.mjs +6 -7
- package/lib/middleware/bun/index.mjs +8 -9
- package/lib/middleware/cloudflare-pages/index.mjs +5 -6
- package/lib/middleware/deno/index.mjs +7 -8
- package/lib/middleware/firebase/index.mjs +4 -5
- package/lib/middleware/netlify-edge/index.mjs +5 -6
- package/lib/middleware/node/index.mjs +15 -11
- package/lib/middleware/request-handler/index.d.ts +2 -2
- package/lib/middleware/request-handler/index.mjs +64 -79
- package/lib/middleware/vercel-edge/index.mjs +5 -6
- package/lib/service-worker/index.mjs +2 -3
- package/lib/ssg/index.mjs +3 -4
- package/lib/vite/index.d.ts +7 -1
- package/lib/vite/index.mjs +91 -68
- package/package.json +21 -39
- package/lib/adapters/azure-swa/vite/index.cjs +0 -61
- package/lib/adapters/bun-server/vite/index.cjs +0 -27
- package/lib/adapters/cloud-run/vite/index.cjs +0 -24
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -65
- package/lib/adapters/deno-server/vite/index.cjs +0 -39
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -88
- package/lib/adapters/node-server/vite/index.cjs +0 -27
- package/lib/adapters/shared/vite/index.cjs +0 -306
- package/lib/adapters/ssg/vite/index.cjs +0 -19
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -81
- package/lib/chunks/error-handler.cjs +0 -58
- package/lib/chunks/format-error.cjs +0 -136
- package/lib/chunks/fs.cjs +0 -274
- package/lib/chunks/index.cjs +0 -877
- package/lib/chunks/mime-types.cjs +0 -52
- package/lib/chunks/routing.qwik.cjs +0 -452
- package/lib/chunks/types.qwik.cjs +0 -24
- package/lib/index.qwik.cjs +0 -1662
- package/lib/middleware/aws-lambda/index.cjs +0 -52
- package/lib/middleware/azure-swa/index.cjs +0 -92
- package/lib/middleware/bun/index.cjs +0 -143
- package/lib/middleware/cloudflare-pages/index.cjs +0 -96
- package/lib/middleware/deno/index.cjs +0 -130
- package/lib/middleware/firebase/index.cjs +0 -33
- package/lib/middleware/netlify-edge/index.cjs +0 -71
- package/lib/middleware/node/index.cjs +0 -219
- package/lib/middleware/request-handler/index.cjs +0 -1488
- package/lib/middleware/vercel-edge/index.cjs +0 -98
- package/lib/service-worker/index.cjs +0 -5
- package/lib/ssg/index.cjs +0 -15
- package/lib/vite/index.cjs +0 -2021
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const node = require("@qwik.dev/router/middleware/node");
|
|
4
|
-
function createQwikRouter(opts) {
|
|
5
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
6
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
7
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
const { router, staticFile, notFound } = node.createQwikRouter({
|
|
11
|
-
render: opts.render,
|
|
12
|
-
qwikRouterConfig: opts.qwikRouterConfig,
|
|
13
|
-
manifest: opts.manifest,
|
|
14
|
-
static: {
|
|
15
|
-
cacheControl: "public, max-age=31557600"
|
|
16
|
-
},
|
|
17
|
-
getOrigin(req) {
|
|
18
|
-
if (process.env.IS_OFFLINE) {
|
|
19
|
-
return `http://${req.headers.host}`;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const fixPath = (pathT) => {
|
|
25
|
-
if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
26
|
-
const url = new URL(pathT, "http://aws-qwik.local");
|
|
27
|
-
if (url.pathname.includes(".", url.pathname.lastIndexOf("/"))) {
|
|
28
|
-
return pathT;
|
|
29
|
-
}
|
|
30
|
-
if (!url.pathname.endsWith("/")) {
|
|
31
|
-
return url.pathname + "/" + url.search;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return pathT;
|
|
35
|
-
};
|
|
36
|
-
const handle = (req, res) => {
|
|
37
|
-
req.url = fixPath(req.url);
|
|
38
|
-
staticFile(req, res, () => {
|
|
39
|
-
router(req, res, () => {
|
|
40
|
-
notFound(req, res, () => {
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
return { fixPath, router, staticFile, notFound, handle };
|
|
46
|
-
} catch (err) {
|
|
47
|
-
throw new Error(err.message);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
const createQwikCity = createQwikRouter;
|
|
51
|
-
exports.createQwikCity = createQwikCity;
|
|
52
|
-
exports.createQwikRouter = createQwikRouter;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("@qwik.dev/core/server");
|
|
4
|
-
const requestHandler = require("@qwik.dev/router/middleware/request-handler");
|
|
5
|
-
const setCookieParser = require("set-cookie-parser");
|
|
6
|
-
function createQwikRouter(opts) {
|
|
7
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
8
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
9
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
10
|
-
}
|
|
11
|
-
if (opts.manifest) {
|
|
12
|
-
server.setServerPlatform(opts.manifest);
|
|
13
|
-
}
|
|
14
|
-
async function onAzureSwaRequest(context, req) {
|
|
15
|
-
try {
|
|
16
|
-
const url = new URL(req.headers["x-ms-original-url"]);
|
|
17
|
-
const options = {
|
|
18
|
-
method: req.method || "GET",
|
|
19
|
-
headers: req.headers,
|
|
20
|
-
body: req.bufferBody || req.rawBody || req.body
|
|
21
|
-
};
|
|
22
|
-
const serverRequestEv = {
|
|
23
|
-
mode: "server",
|
|
24
|
-
locale: void 0,
|
|
25
|
-
url,
|
|
26
|
-
platform: context,
|
|
27
|
-
env: {
|
|
28
|
-
get(key) {
|
|
29
|
-
return process.env[key];
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
request: new Request(url, options),
|
|
33
|
-
getWritableStream: (status, headers, cookies, resolve) => {
|
|
34
|
-
const response = {
|
|
35
|
-
status,
|
|
36
|
-
body: new Uint8Array(),
|
|
37
|
-
headers: {},
|
|
38
|
-
cookies: cookies.headers().map((header) => setCookieParser.parseString(header))
|
|
39
|
-
};
|
|
40
|
-
headers.forEach((value, key) => response.headers[key] = value);
|
|
41
|
-
return new WritableStream({
|
|
42
|
-
write(chunk) {
|
|
43
|
-
if (response.body instanceof Uint8Array) {
|
|
44
|
-
const newBuffer = new Uint8Array(response.body.length + chunk.length);
|
|
45
|
-
newBuffer.set(response.body);
|
|
46
|
-
newBuffer.set(chunk, response.body.length);
|
|
47
|
-
response.body = newBuffer;
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
close() {
|
|
51
|
-
resolve(response);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
},
|
|
55
|
-
getClientConn: () => {
|
|
56
|
-
return {
|
|
57
|
-
ip: req.headers["x-forwarded-client-Ip"],
|
|
58
|
-
country: void 0
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const handledResponse = await requestHandler.requestHandler(serverRequestEv, opts);
|
|
63
|
-
if (handledResponse) {
|
|
64
|
-
handledResponse.completion.then((err) => {
|
|
65
|
-
if (err) {
|
|
66
|
-
console.error(err);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
const response = await handledResponse.response;
|
|
70
|
-
if (response) {
|
|
71
|
-
return response;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const notFoundHtml = !req.headers.accept?.includes("text/html") || requestHandler.isStaticPath(req.method || "GET", url) ? "Not Found" : requestHandler.getNotFound(url.pathname);
|
|
75
|
-
return {
|
|
76
|
-
status: 404,
|
|
77
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname },
|
|
78
|
-
body: notFoundHtml
|
|
79
|
-
};
|
|
80
|
-
} catch (e) {
|
|
81
|
-
console.error(e);
|
|
82
|
-
return {
|
|
83
|
-
status: 500,
|
|
84
|
-
headers: { "Content-Type": "text/plain; charset=utf-8" }
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return onAzureSwaRequest;
|
|
89
|
-
}
|
|
90
|
-
const createQwikCity = createQwikRouter;
|
|
91
|
-
exports.createQwikCity = createQwikCity;
|
|
92
|
-
exports.createQwikRouter = createQwikRouter;
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("@qwik.dev/core/server");
|
|
4
|
-
const requestHandler = require("@qwik.dev/router/middleware/request-handler");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const mimeTypes = require("../../chunks/mime-types.cjs");
|
|
7
|
-
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
8
|
-
function createQwikRouter(opts) {
|
|
9
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
10
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
11
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
12
|
-
}
|
|
13
|
-
globalThis.TextEncoderStream || (globalThis.TextEncoderStream = requestHandler._TextEncoderStream_polyfill);
|
|
14
|
-
if (opts.manifest) {
|
|
15
|
-
server.setServerPlatform(opts.manifest);
|
|
16
|
-
}
|
|
17
|
-
const staticFolder = opts.static?.root ?? path.join(Bun.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("middleware/bun/index.cjs", document.baseURI).href), "..", "..", "dist");
|
|
18
|
-
async function router(request) {
|
|
19
|
-
try {
|
|
20
|
-
const url = new URL(request.url);
|
|
21
|
-
const serverRequestEv = {
|
|
22
|
-
mode: "server",
|
|
23
|
-
locale: void 0,
|
|
24
|
-
url,
|
|
25
|
-
env: {
|
|
26
|
-
get(key) {
|
|
27
|
-
return Bun.env[key];
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
request,
|
|
31
|
-
getWritableStream: (status, headers, cookies, resolve) => {
|
|
32
|
-
const { readable, writable } = new TransformStream();
|
|
33
|
-
const response = new Response(readable, {
|
|
34
|
-
status,
|
|
35
|
-
headers: requestHandler.mergeHeadersCookies(headers, cookies)
|
|
36
|
-
});
|
|
37
|
-
resolve(response);
|
|
38
|
-
return writable;
|
|
39
|
-
},
|
|
40
|
-
platform: {
|
|
41
|
-
ssr: true
|
|
42
|
-
},
|
|
43
|
-
getClientConn: () => {
|
|
44
|
-
return opts.getClientConn ? opts.getClientConn(request) : {};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const handledResponse = await requestHandler.requestHandler(serverRequestEv, opts);
|
|
48
|
-
if (handledResponse) {
|
|
49
|
-
handledResponse.completion.then((v) => {
|
|
50
|
-
if (v) {
|
|
51
|
-
console.error(v);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
const response = await handledResponse.response;
|
|
55
|
-
if (response) {
|
|
56
|
-
const status = response.status;
|
|
57
|
-
const location = response.headers.get("Location");
|
|
58
|
-
const isRedirect = status >= 301 && status <= 308 && location;
|
|
59
|
-
if (isRedirect) {
|
|
60
|
-
return new Response(null, response);
|
|
61
|
-
}
|
|
62
|
-
return response;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.error(e);
|
|
68
|
-
return new Response(String(e || "Error"), {
|
|
69
|
-
status: 500,
|
|
70
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const notFound = async (request) => {
|
|
75
|
-
try {
|
|
76
|
-
const url = new URL(request.url);
|
|
77
|
-
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || requestHandler.isStaticPath(request.method || "GET", url) ? "Not Found" : requestHandler.getNotFound(url.pathname);
|
|
78
|
-
return new Response(notFoundHtml, {
|
|
79
|
-
status: 404,
|
|
80
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
81
|
-
});
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error(e);
|
|
84
|
-
return new Response(String(e || "Error"), {
|
|
85
|
-
status: 500,
|
|
86
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
const openStaticFile = async (url) => {
|
|
91
|
-
const pathname = url.pathname;
|
|
92
|
-
const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
|
|
93
|
-
let filePath;
|
|
94
|
-
if (fileName.includes(".")) {
|
|
95
|
-
filePath = path.join(staticFolder, pathname);
|
|
96
|
-
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
97
|
-
filePath = path.join(staticFolder, pathname + "index.html");
|
|
98
|
-
} else {
|
|
99
|
-
filePath = path.join(staticFolder, pathname, "index.html");
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
filePath,
|
|
103
|
-
content: Bun.file(filePath)
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const staticFile = async (request) => {
|
|
107
|
-
try {
|
|
108
|
-
const url = new URL(request.url);
|
|
109
|
-
if (requestHandler.isStaticPath(request.method || "GET", url)) {
|
|
110
|
-
const { filePath, content } = await openStaticFile(url);
|
|
111
|
-
if (!await content.exists()) {
|
|
112
|
-
return new Response("Not Found", {
|
|
113
|
-
status: 404,
|
|
114
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Not-Found": url.pathname }
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
const ext = path.extname(filePath).replace(/^\./, "");
|
|
118
|
-
return new Response(await content.stream(), {
|
|
119
|
-
status: 200,
|
|
120
|
-
headers: {
|
|
121
|
-
"content-type": mimeTypes.MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
122
|
-
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return null;
|
|
127
|
-
} catch (e) {
|
|
128
|
-
console.error(e);
|
|
129
|
-
return new Response(String(e || "Error"), {
|
|
130
|
-
status: 500,
|
|
131
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "bun-server" }
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
return {
|
|
136
|
-
router,
|
|
137
|
-
notFound,
|
|
138
|
-
staticFile
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
const createQwikCity = createQwikRouter;
|
|
142
|
-
exports.createQwikCity = createQwikCity;
|
|
143
|
-
exports.createQwikRouter = createQwikRouter;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("@qwik.dev/core/server");
|
|
4
|
-
const requestHandler = require("@qwik.dev/router/middleware/request-handler");
|
|
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
|
-
try {
|
|
11
|
-
new globalThis.TextEncoderStream();
|
|
12
|
-
} catch {
|
|
13
|
-
globalThis.TextEncoderStream = requestHandler._TextEncoderStream_polyfill;
|
|
14
|
-
}
|
|
15
|
-
if (opts.manifest) {
|
|
16
|
-
server.setServerPlatform(opts.manifest);
|
|
17
|
-
}
|
|
18
|
-
async function onCloudflarePagesFetch(request, env, ctx) {
|
|
19
|
-
try {
|
|
20
|
-
const url = new URL(request.url);
|
|
21
|
-
if (requestHandler.isStaticPath(request.method, url)) {
|
|
22
|
-
return env.ASSETS.fetch(request);
|
|
23
|
-
}
|
|
24
|
-
const useCache = url.hostname !== "127.0.0.1" && url.hostname !== "localhost" && url.port === "" && request.method === "GET";
|
|
25
|
-
const cacheKey = new Request(url.href, request);
|
|
26
|
-
const cache = useCache ? await caches.open("custom:qwikrouter") : null;
|
|
27
|
-
if (cache) {
|
|
28
|
-
const cachedResponse = await cache.match(cacheKey);
|
|
29
|
-
if (cachedResponse) {
|
|
30
|
-
return cachedResponse;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const serverRequestEv = {
|
|
34
|
-
mode: "server",
|
|
35
|
-
locale: void 0,
|
|
36
|
-
url,
|
|
37
|
-
request,
|
|
38
|
-
env: {
|
|
39
|
-
get(key) {
|
|
40
|
-
return env[key];
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
getWritableStream: (status, headers, cookies, resolve) => {
|
|
44
|
-
const { readable, writable } = new TransformStream();
|
|
45
|
-
const response = new Response(readable, {
|
|
46
|
-
status,
|
|
47
|
-
headers: requestHandler.mergeHeadersCookies(headers, cookies)
|
|
48
|
-
});
|
|
49
|
-
resolve(response);
|
|
50
|
-
return writable;
|
|
51
|
-
},
|
|
52
|
-
getClientConn: () => {
|
|
53
|
-
return {
|
|
54
|
-
ip: request.headers.get("CF-connecting-ip") || "",
|
|
55
|
-
country: request.headers.get("CF-IPCountry") || ""
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
platform: {
|
|
59
|
-
request,
|
|
60
|
-
env,
|
|
61
|
-
ctx
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const handledResponse = await requestHandler.requestHandler(serverRequestEv, opts);
|
|
65
|
-
if (handledResponse) {
|
|
66
|
-
handledResponse.completion.then((v) => {
|
|
67
|
-
if (v) {
|
|
68
|
-
console.error(v);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const response = await handledResponse.response;
|
|
72
|
-
if (response) {
|
|
73
|
-
if (response.ok && cache && response.headers.has("Cache-Control")) {
|
|
74
|
-
ctx.waitUntil(cache.put(cacheKey, response.clone()));
|
|
75
|
-
}
|
|
76
|
-
return response;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || requestHandler.isStaticPath(request.method || "GET", url) ? "Not Found" : requestHandler.getNotFound(url.pathname);
|
|
80
|
-
return new Response(notFoundHtml, {
|
|
81
|
-
status: 404,
|
|
82
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
83
|
-
});
|
|
84
|
-
} catch (e) {
|
|
85
|
-
console.error(e);
|
|
86
|
-
return new Response(String(e || "Error"), {
|
|
87
|
-
status: 500,
|
|
88
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "cloudflare-pages" }
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return onCloudflarePagesFetch;
|
|
93
|
-
}
|
|
94
|
-
const createQwikCity = createQwikRouter;
|
|
95
|
-
exports.createQwikCity = createQwikCity;
|
|
96
|
-
exports.createQwikRouter = createQwikRouter;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("@qwik.dev/core/server");
|
|
4
|
-
const requestHandler = require("@qwik.dev/router/middleware/request-handler");
|
|
5
|
-
const mimeTypes = require("../../chunks/mime-types.cjs");
|
|
6
|
-
const mod_ts = require("https://deno.land/std/path/mod.ts");
|
|
7
|
-
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
8
|
-
function createQwikRouter(opts) {
|
|
9
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
10
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
11
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
12
|
-
}
|
|
13
|
-
if (opts.manifest) {
|
|
14
|
-
server.setServerPlatform(opts.manifest);
|
|
15
|
-
}
|
|
16
|
-
const staticFolder = opts.static?.root ?? mod_ts.join(mod_ts.fromFileUrl(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("middleware/deno/index.cjs", document.baseURI).href), "..", "..", "dist");
|
|
17
|
-
async function router(request, info) {
|
|
18
|
-
try {
|
|
19
|
-
const url = new URL(request.url);
|
|
20
|
-
const serverRequestEv = {
|
|
21
|
-
mode: "server",
|
|
22
|
-
locale: void 0,
|
|
23
|
-
url,
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
env: Deno.env,
|
|
26
|
-
request,
|
|
27
|
-
getWritableStream: (status, headers, cookies, resolve) => {
|
|
28
|
-
const { readable, writable } = new TransformStream();
|
|
29
|
-
const response = new Response(readable, {
|
|
30
|
-
status,
|
|
31
|
-
headers: requestHandler.mergeHeadersCookies(headers, cookies)
|
|
32
|
-
});
|
|
33
|
-
resolve(response);
|
|
34
|
-
return writable;
|
|
35
|
-
},
|
|
36
|
-
platform: {
|
|
37
|
-
ssr: true
|
|
38
|
-
},
|
|
39
|
-
getClientConn: () => {
|
|
40
|
-
return opts.getClientConn ? opts.getClientConn(request, info) : {
|
|
41
|
-
ip: info.remoteAddr.hostname
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
const handledResponse = await requestHandler.requestHandler(serverRequestEv, opts);
|
|
46
|
-
if (handledResponse) {
|
|
47
|
-
handledResponse.completion.then((v) => {
|
|
48
|
-
if (v) {
|
|
49
|
-
console.error(v);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
const response = await handledResponse.response;
|
|
53
|
-
if (response) {
|
|
54
|
-
return response;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.error(e);
|
|
60
|
-
return new Response(String(e || "Error"), {
|
|
61
|
-
status: 500,
|
|
62
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const notFound = async (request) => {
|
|
67
|
-
try {
|
|
68
|
-
const url = new URL(request.url);
|
|
69
|
-
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || requestHandler.isStaticPath(request.method || "GET", url) ? "Not Found" : requestHandler.getNotFound(url.pathname);
|
|
70
|
-
return new Response(notFoundHtml, {
|
|
71
|
-
status: 404,
|
|
72
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
73
|
-
});
|
|
74
|
-
} catch (e) {
|
|
75
|
-
console.error(e);
|
|
76
|
-
return new Response(String(e || "Error"), {
|
|
77
|
-
status: 500,
|
|
78
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const openStaticFile = async (url) => {
|
|
83
|
-
const pathname = url.pathname;
|
|
84
|
-
const fileName = pathname.slice(url.pathname.lastIndexOf("/"));
|
|
85
|
-
let filePath;
|
|
86
|
-
if (fileName.includes(".")) {
|
|
87
|
-
filePath = mod_ts.join(staticFolder, pathname);
|
|
88
|
-
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
89
|
-
filePath = mod_ts.join(staticFolder, pathname + "index.html");
|
|
90
|
-
} else {
|
|
91
|
-
filePath = mod_ts.join(staticFolder, pathname, "index.html");
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
filePath,
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
content: await Deno.open(filePath, { read: true })
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
const staticFile = async (request) => {
|
|
100
|
-
try {
|
|
101
|
-
const url = new URL(request.url);
|
|
102
|
-
if (requestHandler.isStaticPath(request.method || "GET", url)) {
|
|
103
|
-
const { filePath, content } = await openStaticFile(url);
|
|
104
|
-
const ext = mod_ts.extname(filePath).replace(/^\./, "");
|
|
105
|
-
return new Response(content.readable, {
|
|
106
|
-
status: 200,
|
|
107
|
-
headers: {
|
|
108
|
-
"content-type": mimeTypes.MIME_TYPES[ext] || "text/plain; charset=utf-8",
|
|
109
|
-
"Cache-Control": opts.static?.cacheControl || "max-age=3600"
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
} catch (e) {
|
|
115
|
-
console.error(e);
|
|
116
|
-
return new Response(String(e || "Error"), {
|
|
117
|
-
status: 500,
|
|
118
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "deno-server" }
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
return {
|
|
123
|
-
router,
|
|
124
|
-
notFound,
|
|
125
|
-
staticFile
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
const createQwikCity = createQwikRouter;
|
|
129
|
-
exports.createQwikCity = createQwikCity;
|
|
130
|
-
exports.createQwikRouter = createQwikRouter;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const node = require("@qwik.dev/router/middleware/node");
|
|
4
|
-
function createQwikRouter(opts) {
|
|
5
|
-
if (opts.qwikCityPlan && !opts.qwikRouterConfig) {
|
|
6
|
-
console.warn("qwikCityPlan is deprecated. Simply remove it.");
|
|
7
|
-
opts.qwikRouterConfig = opts.qwikCityPlan;
|
|
8
|
-
}
|
|
9
|
-
const { staticFile, notFound, router } = node.createQwikRouter({
|
|
10
|
-
render: opts.render,
|
|
11
|
-
manifest: opts.manifest,
|
|
12
|
-
qwikRouterConfig: opts.qwikRouterConfig,
|
|
13
|
-
static: {
|
|
14
|
-
cacheControl: "public, max-age=31557600"
|
|
15
|
-
},
|
|
16
|
-
getOrigin(req) {
|
|
17
|
-
if (process.env.IS_OFFLINE) {
|
|
18
|
-
return `http://${req.headers.host}`;
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const qwikApp = (req, res) => {
|
|
24
|
-
return staticFile(req, res, () => {
|
|
25
|
-
router(req, res, () => notFound(req, res, () => {
|
|
26
|
-
}));
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
return qwikApp;
|
|
30
|
-
}
|
|
31
|
-
const createQwikCity = createQwikRouter;
|
|
32
|
-
exports.createQwikCity = createQwikCity;
|
|
33
|
-
exports.createQwikRouter = createQwikRouter;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("@qwik.dev/core/server");
|
|
4
|
-
const requestHandler = require("@qwik.dev/router/middleware/request-handler");
|
|
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
|
-
if (opts.manifest) {
|
|
11
|
-
server.setServerPlatform(opts.manifest);
|
|
12
|
-
}
|
|
13
|
-
async function onNetlifyEdgeRequest(request, context) {
|
|
14
|
-
try {
|
|
15
|
-
const url = new URL(request.url);
|
|
16
|
-
if (requestHandler.isStaticPath(request.method, url) || url.pathname.startsWith("/.netlify")) {
|
|
17
|
-
return context.next();
|
|
18
|
-
}
|
|
19
|
-
const serverRequestEv = {
|
|
20
|
-
mode: "server",
|
|
21
|
-
locale: void 0,
|
|
22
|
-
url,
|
|
23
|
-
env: Deno.env,
|
|
24
|
-
request,
|
|
25
|
-
getWritableStream: (status, headers, cookies, resolve) => {
|
|
26
|
-
const { readable, writable } = new TransformStream();
|
|
27
|
-
const response = new Response(readable, {
|
|
28
|
-
status,
|
|
29
|
-
headers: requestHandler.mergeHeadersCookies(headers, cookies)
|
|
30
|
-
});
|
|
31
|
-
resolve(response);
|
|
32
|
-
return writable;
|
|
33
|
-
},
|
|
34
|
-
getClientConn: () => {
|
|
35
|
-
return {
|
|
36
|
-
ip: context.ip,
|
|
37
|
-
country: context.geo.country?.code
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
platform: context
|
|
41
|
-
};
|
|
42
|
-
const handledResponse = await requestHandler.requestHandler(serverRequestEv, opts);
|
|
43
|
-
if (handledResponse) {
|
|
44
|
-
handledResponse.completion.then((v) => {
|
|
45
|
-
if (v) {
|
|
46
|
-
console.error(v);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const response = await handledResponse.response;
|
|
50
|
-
if (response) {
|
|
51
|
-
return response;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const notFoundHtml = !request.headers.get("accept")?.includes("text/html") || requestHandler.isStaticPath(request.method || "GET", url) ? "Not Found" : requestHandler.getNotFound(url.pathname);
|
|
55
|
-
return new Response(notFoundHtml, {
|
|
56
|
-
status: 404,
|
|
57
|
-
headers: { "Content-Type": "text/html; charset=utf-8", "X-Not-Found": url.pathname }
|
|
58
|
-
});
|
|
59
|
-
} catch (e) {
|
|
60
|
-
console.error(e);
|
|
61
|
-
return new Response(String(e || "Error"), {
|
|
62
|
-
status: 500,
|
|
63
|
-
headers: { "Content-Type": "text/plain; charset=utf-8", "X-Error": "netlify-edge" }
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return onNetlifyEdgeRequest;
|
|
68
|
-
}
|
|
69
|
-
const createQwikCity = createQwikRouter;
|
|
70
|
-
exports.createQwikCity = createQwikCity;
|
|
71
|
-
exports.createQwikRouter = createQwikRouter;
|