workers-start 0.1.1 → 0.2.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/CHANGELOG.md +21 -1
- package/README.md +28 -15
- package/biome.preset.json +31 -13
- package/dist/accept.d.ts +18 -0
- package/dist/accept.d.ts.map +1 -0
- package/dist/accept.js +54 -0
- package/dist/accept.js.map +1 -0
- package/dist/check-bundle-cli.d.ts +1 -1
- package/dist/check-bundle-cli.js +50 -25
- package/dist/check-bundle-cli.js.map +1 -1
- package/dist/check-bundle.d.ts +36 -8
- package/dist/check-bundle.d.ts.map +1 -1
- package/dist/check-bundle.js +122 -31
- package/dist/check-bundle.js.map +1 -1
- package/dist/entry.d.ts +40 -18
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +99 -35
- package/dist/entry.js.map +1 -1
- package/dist/head.d.ts +34 -10
- package/dist/head.d.ts.map +1 -1
- package/dist/head.js +46 -26
- package/dist/head.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/scripts.d.ts +34 -6
- package/dist/scripts.d.ts.map +1 -1
- package/dist/scripts.js +36 -11
- package/dist/scripts.js.map +1 -1
- package/dist/workers.d.ts +6 -4
- package/dist/workers.d.ts.map +1 -1
- package/dist/workers.js +17 -13
- package/dist/workers.js.map +1 -1
- package/package.json +21 -9
- package/src/accept.ts +63 -0
- package/src/check-bundle-cli.ts +57 -23
- package/src/check-bundle.ts +133 -34
- package/src/entry.ts +117 -44
- package/src/head.ts +75 -40
- package/src/index.ts +14 -3
- package/src/scripts.ts +62 -14
- package/src/workers.ts +19 -15
package/dist/check-bundle.js
CHANGED
|
@@ -1,37 +1,99 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Finds local secrets compiled into a build.
|
|
3
3
|
*
|
|
4
|
-
* Reads every value in the local `.env*` and `.dev.vars*` files (examples
|
|
5
|
-
* excluded) and searches the built files for each one
|
|
4
|
+
* Reads every value in the local `.env*` and `.dev.vars*` files (examples and
|
|
5
|
+
* `.tpl` templates excluded) and searches the built files for each one, raw
|
|
6
|
+
* and in the encodings a bundler or a URL would give it. A match means a key
|
|
6
7
|
* reached something that ships, whichever tool put it there.
|
|
7
8
|
*/
|
|
8
|
-
import { existsSync, readdirSync, readFileSync
|
|
9
|
-
import { join } from "node:path";
|
|
9
|
+
import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
10
|
+
import { join, relative, sep } from "node:path";
|
|
11
|
+
import { brotliDecompressSync, gunzipSync } from "node:zlib";
|
|
10
12
|
/** Values shorter than this are flags or placeholders, not secrets. */
|
|
11
13
|
export const MIN_SECRET_LENGTH = 12;
|
|
14
|
+
/**
|
|
15
|
+
* Paths, relative to a build directory, that are never uploaded: the copy of
|
|
16
|
+
* the local env the Cloudflare Vite plugin writes for `vite preview`.
|
|
17
|
+
*/
|
|
18
|
+
export const DEFAULT_SKIP = ["server/.dev.vars"];
|
|
19
|
+
/** Keys Vite inlines on purpose; their values are public. */
|
|
20
|
+
export const DEFAULT_PUBLIC_PREFIXES = ["VITE_"];
|
|
12
21
|
const ENV_FILE = /^(\.env(\..+)?|\.dev\.vars(\..+)?)$/;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
const NOT_SECRETS = /\.(example|sample|template|tpl)$/;
|
|
23
|
+
const KEY = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.*)$/;
|
|
24
|
+
const INLINE_COMMENT = /\s+#.*$/;
|
|
25
|
+
const ESCAPES = { n: "\n", r: "\r", t: "\t", '"': '"', "\\": "\\" };
|
|
26
|
+
/**
|
|
27
|
+
* KEY=value pairs from a dotenv file, parsed the way dotenv does: `#`
|
|
28
|
+
* comments, inline ` #` comments on unquoted values, single quotes taken
|
|
29
|
+
* literally, double quotes with `\n` escapes and multi-line values.
|
|
30
|
+
*/
|
|
19
31
|
export function parseEnvFile(source) {
|
|
20
32
|
const pairs = [];
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
const lines = source.replace(/\r\n?/g, "\n").split("\n");
|
|
34
|
+
for (let i = 0; i < lines.length; i++) {
|
|
35
|
+
const match = (lines[i] ?? "").match(KEY);
|
|
23
36
|
if (!(match?.[1] && match[2] !== undefined)) {
|
|
24
37
|
continue;
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
const key = match[1];
|
|
40
|
+
let raw = match[2].trim();
|
|
41
|
+
const quote = raw[0];
|
|
42
|
+
if (quote === '"' || quote === "'" || quote === "`") {
|
|
43
|
+
// Gather lines until the closing quote, for multi-line values.
|
|
44
|
+
let body = raw.slice(1);
|
|
45
|
+
while (!hasClosingQuote(body, quote) && i + 1 < lines.length) {
|
|
46
|
+
i++;
|
|
47
|
+
body += `\n${lines[i]}`;
|
|
48
|
+
}
|
|
49
|
+
const end = closingQuoteIndex(body, quote);
|
|
50
|
+
raw = end === -1 ? body : body.slice(0, end);
|
|
51
|
+
pairs.push([key, quote === '"' ? raw.replace(/\\(.)/g, (m, c) => ESCAPES[c] ?? m) : raw]);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
pairs.push([key, raw.replace(INLINE_COMMENT, "").trim()]);
|
|
55
|
+
}
|
|
27
56
|
}
|
|
28
57
|
return pairs;
|
|
29
58
|
}
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
function closingQuoteIndex(body, quote) {
|
|
60
|
+
for (let i = 0; i < body.length; i++) {
|
|
61
|
+
if (body[i] === "\\" && quote === '"') {
|
|
62
|
+
i++;
|
|
63
|
+
}
|
|
64
|
+
else if (body[i] === quote) {
|
|
65
|
+
return i;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return -1;
|
|
69
|
+
}
|
|
70
|
+
function hasClosingQuote(body, quote) {
|
|
71
|
+
return closingQuoteIndex(body, quote) !== -1;
|
|
72
|
+
}
|
|
73
|
+
/** The forms a value can take once it is in a bundle or a URL. */
|
|
74
|
+
export function encodings(value) {
|
|
75
|
+
const forms = new Set([
|
|
76
|
+
value,
|
|
77
|
+
encodeURIComponent(value),
|
|
78
|
+
JSON.stringify(value).slice(1, -1),
|
|
79
|
+
Buffer.from(value).toString("base64").replace(/=+$/, ""),
|
|
80
|
+
Buffer.from(value).toString("base64url").replace(/=+$/, ""),
|
|
81
|
+
]);
|
|
82
|
+
return [...forms].filter((form) => form.length >= MIN_SECRET_LENGTH);
|
|
83
|
+
}
|
|
84
|
+
/** The env keys whose values appear, in any encoding, in any of the given file contents. */
|
|
85
|
+
export function leakedKeys(pairs, contents, options = {}) {
|
|
86
|
+
const publicPrefixes = options.publicPrefixes ?? DEFAULT_PUBLIC_PREFIXES;
|
|
32
87
|
const leaked = new Set();
|
|
33
88
|
for (const [key, value] of pairs) {
|
|
34
|
-
if (value.length
|
|
89
|
+
if (value.length < MIN_SECRET_LENGTH || value.startsWith("op://")) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (options.allow?.includes(key) || publicPrefixes.some((prefix) => key.startsWith(prefix))) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const forms = encodings(value);
|
|
96
|
+
if (contents.some((text) => forms.some((form) => text.includes(form)))) {
|
|
35
97
|
leaked.add(key);
|
|
36
98
|
}
|
|
37
99
|
}
|
|
@@ -40,30 +102,59 @@ export function leakedKeys(pairs, contents) {
|
|
|
40
102
|
/** Every KEY=value pair in the local env files of `dir`. */
|
|
41
103
|
export function localEnvPairs(dir) {
|
|
42
104
|
return readdirSync(dir)
|
|
43
|
-
.filter((name) => ENV_FILE.test(name) && !
|
|
105
|
+
.filter((name) => ENV_FILE.test(name) && !NOT_SECRETS.test(name))
|
|
44
106
|
.flatMap((name) => parseEnvFile(readFileSync(join(dir, name), "utf8")));
|
|
45
107
|
}
|
|
46
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Every regular file under `dir`, recursively. Symlinks are skipped, so the
|
|
110
|
+
* walk never loops or leaves the directory. `skip` holds paths relative to
|
|
111
|
+
* `dir`, with forward slashes.
|
|
112
|
+
*/
|
|
47
113
|
export function listFiles(dir, skip = DEFAULT_SKIP) {
|
|
48
114
|
const files = [];
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
115
|
+
const walk = (current) => {
|
|
116
|
+
for (const name of readdirSync(current)) {
|
|
117
|
+
const path = join(current, name);
|
|
118
|
+
const stat = lstatSync(path);
|
|
119
|
+
if (stat.isSymbolicLink()) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (stat.isDirectory()) {
|
|
123
|
+
walk(path);
|
|
124
|
+
}
|
|
125
|
+
else if (stat.isFile() && !skip.includes(relative(dir, path).split(sep).join("/"))) {
|
|
126
|
+
files.push(path);
|
|
127
|
+
}
|
|
53
128
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
129
|
+
};
|
|
130
|
+
walk(dir);
|
|
58
131
|
return files;
|
|
59
132
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
133
|
+
/** File contents as text, decompressing `.gz` and `.br` files. */
|
|
134
|
+
export function readBuilt(path) {
|
|
135
|
+
const bytes = readFileSync(path);
|
|
136
|
+
try {
|
|
137
|
+
if (path.endsWith(".gz"))
|
|
138
|
+
return gunzipSync(bytes).toString("latin1");
|
|
139
|
+
if (path.endsWith(".br"))
|
|
140
|
+
return brotliDecompressSync(bytes).toString("latin1");
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Not really compressed; scan the bytes as they are.
|
|
144
|
+
}
|
|
145
|
+
return bytes.toString("latin1");
|
|
146
|
+
}
|
|
147
|
+
/** Scan one or more build directories against the local env files in `root`. */
|
|
148
|
+
export function checkBundle(root, dists, options = {}) {
|
|
149
|
+
const dirs = typeof dists === "string" ? [dists] : dists;
|
|
150
|
+
for (const dir of dirs) {
|
|
151
|
+
if (!existsSync(dir)) {
|
|
152
|
+
throw new Error(`${dir} does not exist. Build first.`);
|
|
153
|
+
}
|
|
63
154
|
}
|
|
64
155
|
const pairs = localEnvPairs(root);
|
|
65
|
-
const files = listFiles(
|
|
66
|
-
const leaked = leakedKeys(pairs, files.map(
|
|
156
|
+
const files = dirs.flatMap((dir) => listFiles(dir, options.skip ?? DEFAULT_SKIP));
|
|
157
|
+
const leaked = leakedKeys(pairs, files.map(readBuilt), options);
|
|
67
158
|
return { envValues: pairs.length, files: files.length, leaked };
|
|
68
159
|
}
|
|
69
160
|
//# sourceMappingURL=check-bundle.js.map
|
package/dist/check-bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-bundle.js","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"check-bundle.js","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7D,uEAAuE;AACvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEjD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAO,CAAC,CAAC;AAEjD,MAAM,QAAQ,GAAG,qCAAqC,CAAC;AACvD,MAAM,WAAW,GAAG,kCAAkC,CAAC;AACvD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AACvE,MAAM,cAAc,GAAG,SAAS,CAAC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,GAAG,+BAA+B,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;AAClE,CAAC"}
|
package/dist/entry.d.ts
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* A Worker entry that sits in front of a TanStack Start handler (or any
|
|
3
3
|
* `{ fetch }` handler) and fixes what Start leaves to the app:
|
|
4
4
|
*
|
|
5
|
-
* - A page request
|
|
6
|
-
*
|
|
7
|
-
* - A page request whose Accept header
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* - Paths under a read-only prefix (default `/api
|
|
11
|
-
* than GET and
|
|
5
|
+
* - A page request that prefers text/markdown gets the Markdown rendering the
|
|
6
|
+
* app provides, on the same URL.
|
|
7
|
+
* - A page request whose Accept header rules out HTML gets HTML anyway,
|
|
8
|
+
* instead of Start's 406.
|
|
9
|
+
* - When Markdown is on, every page response carries `Vary: Accept`.
|
|
10
|
+
* - Paths under a read-only prefix (default `/api`) answer OPTIONS with 204
|
|
11
|
+
* and anything other than GET, HEAD and OPTIONS with 405, instead of an
|
|
12
|
+
* empty 200 page shell.
|
|
12
13
|
*/
|
|
13
14
|
type MaybePromise<T> = T | Promise<T>;
|
|
14
15
|
/** What a Markdown renderer returns: a body, a body with a status, or null to serve HTML. */
|
|
@@ -23,24 +24,45 @@ export interface EntryOptions {
|
|
|
23
24
|
/** The framework handler, usually the default export of `@tanstack/react-start/server-entry`. */
|
|
24
25
|
handler: FetchHandler;
|
|
25
26
|
/**
|
|
26
|
-
* Markdown rendering of a page. Called for GET and HEAD page requests
|
|
27
|
-
*
|
|
27
|
+
* Markdown rendering of a page. Called for GET and HEAD page requests that
|
|
28
|
+
* prefer text/markdown, with the decoded path, no trailing slash. Return
|
|
29
|
+
* null to serve HTML instead. If it throws, the error is logged and HTML is
|
|
30
|
+
* served.
|
|
28
31
|
*/
|
|
29
|
-
markdown?: (
|
|
30
|
-
/** Path prefixes that only accept GET and HEAD. Default `["/api/"]`. Pass `[]` to turn off. */
|
|
31
|
-
readOnlyPrefixes?: string[];
|
|
32
|
+
markdown?: (path: string, request: Request) => MaybePromise<MarkdownResult>;
|
|
32
33
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Path prefixes that only accept GET, HEAD and OPTIONS. Matched by segment,
|
|
35
|
+
* case-insensitively, after decoding: `/api` covers `/api`, `/api/x` and
|
|
36
|
+
* `/API/x`, not `/apiary`. Default `["/api"]`. Pass `[]` to turn off.
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
readOnlyPrefixes?: string[];
|
|
39
|
+
/** Whether a path is a page. Receives the normalized path. Default: {@link defaultIsPage}. */
|
|
40
|
+
isPage?: (path: string) => boolean;
|
|
38
41
|
}
|
|
39
42
|
export declare const MARKDOWN_HEADERS: Readonly<Record<string, string>>;
|
|
43
|
+
/**
|
|
44
|
+
* True when the client names text/markdown with q > 0 and rates it at least
|
|
45
|
+
* as high as HTML. Wildcards alone never select Markdown.
|
|
46
|
+
*/
|
|
40
47
|
export declare function wantsMarkdown(request: Request): boolean;
|
|
41
|
-
export declare function
|
|
42
|
-
/**
|
|
48
|
+
export declare function acceptsHtml(request: Request): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Decodes the path, collapses repeated slashes and drops trailing ones:
|
|
51
|
+
* `/learn//caf%C3%A9/` becomes `/learn/café`. `/` stays `/`. A path that is
|
|
52
|
+
* not valid percent-encoding is returned with only the slash fixes.
|
|
53
|
+
*/
|
|
43
54
|
export declare function normalizePath(pathname: string): string;
|
|
55
|
+
/** Whether `path` sits under `prefix`, by whole segments and ignoring case. */
|
|
56
|
+
export declare function underPrefix(path: string, prefix: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Default page test: not under a read-only prefix, not a Start or Vite
|
|
59
|
+
* internal (`/_…`, `/@vite/…` and similar), and no file extension such as
|
|
60
|
+
* `.js` or `.xml` on the last segment. A dotted slug like `/blog/node.js-tips`
|
|
61
|
+
* is still a page.
|
|
62
|
+
*/
|
|
63
|
+
export declare function defaultIsPage(path: string, readOnlyPrefixes?: readonly string[]): boolean;
|
|
64
|
+
/** Appends `token` to a Vary header value unless it is already there or the value is `*`. */
|
|
65
|
+
export declare function mergeVary(existing: string | null, token: string): string;
|
|
44
66
|
export declare function createEntry(options: EntryOptions): {
|
|
45
67
|
fetch(request: Request, ...rest: unknown[]): Promise<Response>;
|
|
46
68
|
};
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,6FAA6F;AAC7F,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,CAAC;AAE3F,MAAM,WAAW,YAAY;IAE3B,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG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77 +2,141 @@
|
|
|
2
2
|
* A Worker entry that sits in front of a TanStack Start handler (or any
|
|
3
3
|
* `{ fetch }` handler) and fixes what Start leaves to the app:
|
|
4
4
|
*
|
|
5
|
-
* - A page request
|
|
6
|
-
*
|
|
7
|
-
* - A page request whose Accept header
|
|
8
|
-
*
|
|
9
|
-
* -
|
|
10
|
-
* - Paths under a read-only prefix (default `/api
|
|
11
|
-
* than GET and
|
|
5
|
+
* - A page request that prefers text/markdown gets the Markdown rendering the
|
|
6
|
+
* app provides, on the same URL.
|
|
7
|
+
* - A page request whose Accept header rules out HTML gets HTML anyway,
|
|
8
|
+
* instead of Start's 406.
|
|
9
|
+
* - When Markdown is on, every page response carries `Vary: Accept`.
|
|
10
|
+
* - Paths under a read-only prefix (default `/api`) answer OPTIONS with 204
|
|
11
|
+
* and anything other than GET, HEAD and OPTIONS with 405, instead of an
|
|
12
|
+
* empty 200 page shell.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
import { parseAccept, quality } from "./accept.js";
|
|
15
|
+
/** Last-segment extensions that mark a file rather than a page. */
|
|
16
|
+
const FILE_EXTENSION = /\.(?:js|mjs|cjs|css|map|json|xml|txt|md|csv|ico|png|jpe?g|gif|svg|webp|avif|bmp|woff2?|ttf|otf|eot|pdf|mp[34]|webm|wav|ogg|zip|gz|br|wasm|webmanifest|html?|rss|atom)$/i;
|
|
17
|
+
const DEV_INTERNALS = ["/@vite/", "/@fs/", "/@id/", "/@react-refresh", "/node_modules/"];
|
|
18
|
+
const DUPLICATE_SLASHES = /\/{2,}/g;
|
|
14
19
|
const TRAILING_SLASHES = /\/+$/;
|
|
15
|
-
export const MARKDOWN_HEADERS = {
|
|
20
|
+
export const MARKDOWN_HEADERS = Object.freeze({
|
|
16
21
|
"content-type": "text/markdown; charset=utf-8",
|
|
17
22
|
vary: "Accept",
|
|
18
23
|
// A Markdown body is a second representation of a page, not a page of its own.
|
|
19
24
|
"x-robots-tag": "noindex",
|
|
20
|
-
};
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* True when the client names text/markdown with q > 0 and rates it at least
|
|
28
|
+
* as high as HTML. Wildcards alone never select Markdown.
|
|
29
|
+
*/
|
|
21
30
|
export function wantsMarkdown(request) {
|
|
22
|
-
|
|
31
|
+
const ranges = parseAccept(request.headers.get("accept"));
|
|
32
|
+
const markdown = quality(ranges, "text/markdown", { exactOnly: true });
|
|
33
|
+
return markdown > 0 && markdown >= quality(ranges, "text/html");
|
|
34
|
+
}
|
|
35
|
+
export function acceptsHtml(request) {
|
|
36
|
+
return quality(parseAccept(request.headers.get("accept")), "text/html") > 0;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Decodes the path, collapses repeated slashes and drops trailing ones:
|
|
40
|
+
* `/learn//caf%C3%A9/` becomes `/learn/café`. `/` stays `/`. A path that is
|
|
41
|
+
* not valid percent-encoding is returned with only the slash fixes.
|
|
42
|
+
*/
|
|
43
|
+
export function normalizePath(pathname) {
|
|
44
|
+
let path = pathname;
|
|
45
|
+
try {
|
|
46
|
+
path = decodeURIComponent(pathname);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Malformed escapes: match on the raw path.
|
|
50
|
+
}
|
|
51
|
+
path = path.replace(DUPLICATE_SLASHES, "/");
|
|
52
|
+
return path.length > 1 ? path.replace(TRAILING_SLASHES, "") || "/" : path;
|
|
53
|
+
}
|
|
54
|
+
/** Whether `path` sits under `prefix`, by whole segments and ignoring case. */
|
|
55
|
+
export function underPrefix(path, prefix) {
|
|
56
|
+
const p = path.toLowerCase();
|
|
57
|
+
const base = prefix.toLowerCase().replace(TRAILING_SLASHES, "");
|
|
58
|
+
return base === "" || p === base || p.startsWith(`${base}/`);
|
|
23
59
|
}
|
|
24
|
-
|
|
25
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Default page test: not under a read-only prefix, not a Start or Vite
|
|
62
|
+
* internal (`/_…`, `/@vite/…` and similar), and no file extension such as
|
|
63
|
+
* `.js` or `.xml` on the last segment. A dotted slug like `/blog/node.js-tips`
|
|
64
|
+
* is still a page.
|
|
65
|
+
*/
|
|
66
|
+
export function defaultIsPage(path, readOnlyPrefixes = ["/api"]) {
|
|
67
|
+
if (readOnlyPrefixes.some((prefix) => underPrefix(path, prefix))) {
|
|
26
68
|
return false;
|
|
27
69
|
}
|
|
28
|
-
if (
|
|
70
|
+
if (path.startsWith("/_") || DEV_INTERNALS.some((prefix) => path.startsWith(prefix))) {
|
|
29
71
|
return false;
|
|
30
72
|
}
|
|
31
|
-
|
|
32
|
-
return !lastSegment.includes(".");
|
|
73
|
+
return !FILE_EXTENSION.test(path);
|
|
33
74
|
}
|
|
34
|
-
/**
|
|
35
|
-
export function
|
|
36
|
-
|
|
75
|
+
/** Appends `token` to a Vary header value unless it is already there or the value is `*`. */
|
|
76
|
+
export function mergeVary(existing, token) {
|
|
77
|
+
if (!existing?.trim()) {
|
|
78
|
+
return token;
|
|
79
|
+
}
|
|
80
|
+
const tokens = existing.split(",").map((t) => t.trim().toLowerCase());
|
|
81
|
+
if (tokens.includes("*") || tokens.includes(token.toLowerCase())) {
|
|
82
|
+
return existing;
|
|
83
|
+
}
|
|
84
|
+
return `${existing}, ${token}`;
|
|
37
85
|
}
|
|
86
|
+
const NULL_BODY_STATUS = new Set([101, 204, 205, 304]);
|
|
38
87
|
function markdownResponse(result, head) {
|
|
39
88
|
const { body, status = 200 } = typeof result === "string" ? { body: result } : result;
|
|
40
|
-
|
|
89
|
+
const noBody = head || NULL_BODY_STATUS.has(status);
|
|
90
|
+
return new Response(noBody ? null : body, { status, headers: MARKDOWN_HEADERS });
|
|
41
91
|
}
|
|
42
92
|
function withVaryAccept(response) {
|
|
43
|
-
|
|
93
|
+
const vary = mergeVary(response.headers.get("vary"), "Accept");
|
|
94
|
+
if (vary === response.headers.get("vary")) {
|
|
44
95
|
return response;
|
|
45
96
|
}
|
|
46
97
|
const headers = new Headers(response.headers);
|
|
47
|
-
headers.
|
|
98
|
+
headers.set("vary", vary);
|
|
48
99
|
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
49
100
|
}
|
|
50
101
|
export function createEntry(options) {
|
|
51
|
-
const readOnlyPrefixes = options.readOnlyPrefixes ?? ["/api
|
|
52
|
-
const isPage = options.isPage ?? ((
|
|
102
|
+
const readOnlyPrefixes = options.readOnlyPrefixes ?? ["/api"];
|
|
103
|
+
const isPage = options.isPage ?? ((path) => defaultIsPage(path, readOnlyPrefixes));
|
|
53
104
|
return {
|
|
54
105
|
async fetch(request, ...rest) {
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
106
|
+
const path = normalizePath(new URL(request.url).pathname);
|
|
107
|
+
const method = request.method.toUpperCase();
|
|
108
|
+
const isRead = method === "GET" || method === "HEAD";
|
|
109
|
+
if (readOnlyPrefixes.some((prefix) => underPrefix(path, prefix))) {
|
|
110
|
+
if (method === "OPTIONS") {
|
|
111
|
+
return new Response(null, { status: 204, headers: { allow: "GET, HEAD, OPTIONS" } });
|
|
112
|
+
}
|
|
113
|
+
if (!isRead) {
|
|
114
|
+
return Response.json({ error: "Method not allowed" }, { status: 405, headers: { allow: "GET, HEAD, OPTIONS" } });
|
|
115
|
+
}
|
|
116
|
+
return options.handler.fetch(request, ...rest);
|
|
59
117
|
}
|
|
60
|
-
if (!isPage(
|
|
118
|
+
if (!(isRead && isPage(path))) {
|
|
61
119
|
return options.handler.fetch(request, ...rest);
|
|
62
120
|
}
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
121
|
+
if (options.markdown && wantsMarkdown(request)) {
|
|
122
|
+
try {
|
|
123
|
+
const result = await options.markdown(path, request);
|
|
124
|
+
if (result !== null && result !== undefined) {
|
|
125
|
+
return markdownResponse(result, method === "HEAD");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error("workers-start: markdown renderer failed, serving HTML", error);
|
|
67
130
|
}
|
|
68
131
|
}
|
|
69
132
|
let pageRequest = request;
|
|
70
|
-
if (
|
|
133
|
+
if (!acceptsHtml(request)) {
|
|
71
134
|
const headers = new Headers(request.headers);
|
|
72
135
|
headers.set("accept", "text/html");
|
|
73
136
|
pageRequest = new Request(request, { headers });
|
|
74
137
|
}
|
|
75
|
-
|
|
138
|
+
const response = await options.handler.fetch(pageRequest, ...rest);
|
|
139
|
+
return options.markdown ? withVaryAccept(response) : response;
|
|
76
140
|
},
|
|
77
141
|
};
|
|
78
142
|
}
|
package/dist/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAgCnD,mEAAmE;AACnE,MAAM,cAAc,GAClB,yKAAyK,CAAC;AAC5K,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;AACzF,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,CAAC,MAAM,gBAAgB,GAAqC,MAAM,CAAC,MAAM,CAAC;IAC9E,cAAc,EAAE,8BAA8B;IAC9C,IAAI,EAAE,QAAQ;IACd,+EAA+E;IAC/E,cAAc,EAAE,SAAS;CAC1B,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,eAAe,EAAE,EAAE,SAAS,EAAE,I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AgB,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;oBACrD,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,OAAO,CAAC,KAAK,CAAC,uDAAuD,EAAE,KAAK,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;YAED,IAAI,WAAW,GAAG,OAAO,CAAC;YAC1B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC1B,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC7C,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;gBACnC,WAAW,GAAG,IAAI,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;YAClD,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,CAAC;YACnE,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QAChE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/head.d.ts
CHANGED
|
@@ -2,24 +2,36 @@
|
|
|
2
2
|
* Per-page head tags in the shape a TanStack Router `head()` returns.
|
|
3
3
|
*
|
|
4
4
|
* The router keeps one meta per `name` or `property`, deepest route winning,
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* and concatenates links. So call `pageHead` from leaf routes only: a tag a
|
|
6
|
+
* leaf leaves out falls back to a parent's, and a canonical from both a
|
|
7
|
+
* layout and a leaf is emitted twice. Put site-wide tags (charset, viewport,
|
|
8
|
+
* icons) in the root route without this helper.
|
|
8
9
|
*/
|
|
9
10
|
export interface SiteHead {
|
|
10
|
-
/** Absolute origin
|
|
11
|
+
/** Absolute origin: `https://example.com`. A trailing slash is ignored. */
|
|
11
12
|
url: string;
|
|
12
13
|
/** Used for `og:site_name` and the default title suffix. */
|
|
13
14
|
name: string;
|
|
14
|
-
/** Path under the site of the default share image. */
|
|
15
|
+
/** Path under the site, or an absolute URL, of the default share image. */
|
|
15
16
|
defaultImage?: string;
|
|
16
|
-
/**
|
|
17
|
+
/** Author's handle with the @, for `twitter:creator`. */
|
|
17
18
|
twitterCreator?: string;
|
|
19
|
+
/** Site's handle with the @, for `twitter:site`. */
|
|
20
|
+
twitterSite?: string;
|
|
18
21
|
/** Default `en_US`. */
|
|
19
22
|
locale?: string;
|
|
20
23
|
/** Default `(title) => \`${title} | ${name}\``. */
|
|
21
24
|
titleTemplate?: (title: string) => string;
|
|
22
25
|
}
|
|
26
|
+
export interface PageImage {
|
|
27
|
+
/** Path under the site, or an absolute URL. */
|
|
28
|
+
url: string;
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
alt?: string;
|
|
32
|
+
/** MIME type, such as `image/png`. */
|
|
33
|
+
type?: string;
|
|
34
|
+
}
|
|
23
35
|
export interface PageSeo {
|
|
24
36
|
title: string;
|
|
25
37
|
/** Use `title` as the whole document title, without the template. */
|
|
@@ -34,19 +46,31 @@ export interface PageSeo {
|
|
|
34
46
|
socialDescription?: string;
|
|
35
47
|
/** Defaults to `socialDescription`. */
|
|
36
48
|
twitterDescription?: string;
|
|
37
|
-
/**
|
|
38
|
-
image?: string;
|
|
49
|
+
/** A path or URL, or an object with size, alt and type. Defaults to the site's image. */
|
|
50
|
+
image?: string | PageImage;
|
|
51
|
+
/** @deprecated Use `image: { url, width, height, alt }`. */
|
|
39
52
|
imageSize?: {
|
|
40
53
|
width: number;
|
|
41
54
|
height: number;
|
|
42
|
-
alt
|
|
55
|
+
alt?: string;
|
|
43
56
|
};
|
|
44
57
|
/** ISO date, for articles. */
|
|
45
58
|
published?: string;
|
|
46
59
|
/** ISO date, for articles. */
|
|
47
60
|
modified?: string;
|
|
48
|
-
/**
|
|
61
|
+
/** For articles: author names or profile URLs, one `article:author` each. */
|
|
62
|
+
authors?: string[];
|
|
63
|
+
/** For articles: one `article:tag` each. */
|
|
64
|
+
tags?: string[];
|
|
65
|
+
keywords?: string[];
|
|
66
|
+
/** Adds `robots: noindex`. Ignored when `robots` is set. */
|
|
49
67
|
noindex?: boolean;
|
|
68
|
+
/** Full robots directive, such as `noindex, follow` or `max-image-preview:large`. */
|
|
69
|
+
robots?: string;
|
|
70
|
+
/** Override the canonical URL, or `false` to emit none. Defaults to the page URL. */
|
|
71
|
+
canonical?: string | false;
|
|
72
|
+
/** Extra tags, appended last. */
|
|
73
|
+
meta?: MetaTag[];
|
|
50
74
|
}
|
|
51
75
|
export type MetaTag = {
|
|
52
76
|
title: string;
|
package/dist/head.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../src/head.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../src/head.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,WAAW,QAAQ;IACvB,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAED,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG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