@lukoweb/apitogo 0.2.65 → 0.2.66
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/dist/cli/cli.js +1 -1
- package/dist/cli/worker.js +6 -1
- package/package.json +1 -1
- package/src/vite/prerender/utils.ts +12 -0
- package/src/vite/prerender/worker.ts +2 -2
package/dist/cli/cli.js
CHANGED
|
@@ -11433,7 +11433,7 @@ import {
|
|
|
11433
11433
|
// package.json
|
|
11434
11434
|
var package_default = {
|
|
11435
11435
|
name: "@lukoweb/apitogo",
|
|
11436
|
-
version: "0.2.
|
|
11436
|
+
version: "0.2.66",
|
|
11437
11437
|
type: "module",
|
|
11438
11438
|
sideEffects: [
|
|
11439
11439
|
"**/*.css",
|
package/dist/cli/worker.js
CHANGED
|
@@ -115,6 +115,11 @@ var ProtectedRoutesSchema = z.pipe(
|
|
|
115
115
|
|
|
116
116
|
// src/vite/prerender/utils.ts
|
|
117
117
|
var prerenderFileFor = (urlPath) => urlPath === "/" ? "/index.html" : urlPath.endsWith("/index") ? `${urlPath}/index.html` : `${urlPath}.html`;
|
|
118
|
+
var SCRIPT_SAFE_LT = `${"\\"}u003c`;
|
|
119
|
+
var redirectPageHtml = (to) => (
|
|
120
|
+
// Every `<` of the target becomes SCRIPT_SAFE_LT, so a target can never close the script early.
|
|
121
|
+
`<!doctype html><link rel="icon" href="data:,"><script>window.location.href=${JSON.stringify(to).replaceAll("<", SCRIPT_SAFE_LT)};</script>`
|
|
122
|
+
);
|
|
118
123
|
|
|
119
124
|
// src/vite/prerender/worker.ts
|
|
120
125
|
var { template, distDir, serverConfigPath, entryServerPath, writeRedirects } = Piscina.workerData;
|
|
@@ -149,7 +154,7 @@ var renderPage = async ({ urlPath }) => {
|
|
|
149
154
|
if ([301, 302, 303, 307, 308].includes(response.status)) {
|
|
150
155
|
const redirectTo = response.headers.get("Location") ?? "";
|
|
151
156
|
if (writeRedirects) {
|
|
152
|
-
const redirectHtml =
|
|
157
|
+
const redirectHtml = redirectPageHtml(redirectTo);
|
|
153
158
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
154
159
|
await fs.writeFile(outputPath, redirectHtml);
|
|
155
160
|
}
|
package/package.json
CHANGED
|
@@ -87,3 +87,15 @@ export const routesToPaths = (routes: RouteObject[]): string[] =>
|
|
|
87
87
|
|
|
88
88
|
export const routesToRewrites = (routes: RouteObject[]): RouteRewrite[] =>
|
|
89
89
|
collectRewrites(resolveRoutes(routes));
|
|
90
|
+
|
|
91
|
+
/** `<` as a JavaScript string escape: a backslash, then u003c. */
|
|
92
|
+
const SCRIPT_SAFE_LT = `${"\\"}u003c`;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The page written for a route that redirects, such as `/` of a portal without a home page of its own. It declares an
|
|
96
|
+
* empty icon: without one the browser asks for /favicon.ico before the script runs, a 404 and a console error on every
|
|
97
|
+
* visit of the home page (API-134).
|
|
98
|
+
*/
|
|
99
|
+
export const redirectPageHtml = (to: string): string =>
|
|
100
|
+
// Every `<` of the target becomes SCRIPT_SAFE_LT, so a target can never close the script early.
|
|
101
|
+
`<!doctype html><link rel="icon" href="data:,"><script>window.location.href=${JSON.stringify(to).replaceAll("<", SCRIPT_SAFE_LT)};</script>`;
|
|
@@ -7,7 +7,7 @@ import type { ZudokuConfig } from "../../config/validators/ZudokuConfig.js";
|
|
|
7
7
|
import { runPluginTransformConfig } from "../../lib/core/transform-config.js";
|
|
8
8
|
import { joinUrl } from "../../lib/util/joinUrl.js";
|
|
9
9
|
import type { WorkerResult } from "./prerender.js";
|
|
10
|
-
import { prerenderFileFor } from "./utils.js";
|
|
10
|
+
import { prerenderFileFor, redirectPageHtml } from "./utils.js";
|
|
11
11
|
|
|
12
12
|
type EntryServer = typeof import("../../app/entry.server.js");
|
|
13
13
|
|
|
@@ -75,7 +75,7 @@ const renderPage = async ({ urlPath }: WorkerData): Promise<WorkerResult> => {
|
|
|
75
75
|
const redirectTo = response.headers.get("Location") ?? "";
|
|
76
76
|
|
|
77
77
|
if (writeRedirects) {
|
|
78
|
-
const redirectHtml =
|
|
78
|
+
const redirectHtml = redirectPageHtml(redirectTo);
|
|
79
79
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
80
80
|
await fs.writeFile(outputPath, redirectHtml);
|
|
81
81
|
}
|