workers-start 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-11-17)
4
+
5
+ First release, extracted from sites moved from Next.js to TanStack Start on Workers.
6
+
7
+ - `workers-start/entry`: `createEntry`, with Markdown on the same URL for `Accept: text/markdown`, HTML instead of 406 for other Accept values, `Vary: Accept` on pages, and 405 for writes under `/api/`.
8
+ - `workers-start/head`: `createPageHead`, a full title, canonical, Open Graph and Twitter set per page.
9
+ - `workers-start/workers`: lazy `cloudflare:workers` bindings, env and `waitUntil`.
10
+ - `workers-start/scripts`: `themeScript` and `analyticsScript`.
11
+ - `workers-start-check-bundle`: fails a deploy when a local env value appears in a built file.
12
+ - `workers-start/biome`: shared Biome preset.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ryan Ghods
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,119 @@
1
- # Temporary Holding Version
1
+ # workers-start
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The parts every TanStack Start app on Cloudflare Workers ends up writing by hand.
4
+
5
+ It has no runtime dependencies. Each piece is its own entry point, so an app takes only what it uses.
6
+
7
+ ## Why
8
+
9
+ This came out of moving my sites from Next.js on OpenNext to TanStack Start on Workers. Each migration hit the same problems, and each app had started to solve them its own way:
10
+
11
+ - Start answers a page request with 406 unless the Accept header allows HTML. Next served those clients HTML, so moving breaks any crawler or agent that asks for something else.
12
+ - A server route with no handler for a method renders an empty 200 page shell instead of 405, so a `POST` to a GET-only API looks like it worked.
13
+ - Agents increasingly ask for `Accept: text/markdown`. Serving Markdown on the same URL is easy to get half right: the Markdown response says `Vary: Accept` and the HTML one doesn't, so a cache can hand one to the other.
14
+ - The router keeps one `<meta>` per name, deepest route winning. A page that sets its title but not its Twitter tags quietly shares the homepage's card. Under Next, three pages on one of these sites were already shipping the homepage's Twitter card, from the same kind of merge.
15
+ - `cloudflare:workers` only resolves inside workerd. Import it at the top of a module the client bundle or vitest also loads, and the build or the tests break.
16
+ - The Cloudflare Vite plugin copies your local env into `dist/server/.dev.vars` for `vite preview`. wrangler doesn't upload it, but nothing checks that no local secret reached a file that does ship.
17
+
18
+ ## Install
19
+
20
+ ```sh
21
+ npm install workers-start
22
+ ```
23
+
24
+ ## Worker entry
25
+
26
+ `workers-start/entry` wraps the Start handler.
27
+
28
+ ```ts
29
+ // src/server.ts
30
+ import handler, { createServerEntry } from "@tanstack/react-start/server-entry";
31
+ import { createEntry } from "workers-start/entry";
32
+ import { renderMarkdown } from "./markdown";
33
+
34
+ export default createServerEntry(createEntry({ handler, markdown: renderMarkdown }));
35
+ ```
36
+
37
+ Point `main` in `wrangler.jsonc` at this file (`"main": "./src/server.ts"`). Pointing it at `@tanstack/react-start/server-entry` skips your entry without an error.
38
+
39
+ What it does to each request:
40
+
41
+ | Request | Response |
42
+ | ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
43
+ | Page, `Accept: text/markdown` | Your `markdown(path)` result as `text/markdown`, with `Vary: Accept` and `X-Robots-Tag: noindex`. Return a string, `{ body, status }`, or `null` to serve HTML. |
44
+ | Page, Accept names neither HTML nor `*/*` | HTML, not 406 |
45
+ | Any HTML page | `Vary: Accept` added |
46
+ | Non-GET/HEAD under `/api/` | 405 with `Allow: GET, HEAD` |
47
+ | API routes, files with an extension, `/_…`, `/@…` | Passed through untouched |
48
+
49
+ `readOnlyPrefixes` and `isPage` change which paths count as API and which as pages.
50
+
51
+ ## Head tags
52
+
53
+ `workers-start/head` writes a full head set for every page, so nothing inherits the homepage's share card.
54
+
55
+ ```ts
56
+ // lib/seo.ts
57
+ import { createPageHead } from "workers-start/head";
58
+
59
+ export const { pageHead } = createPageHead({
60
+ url: "https://example.com",
61
+ name: "Example",
62
+ defaultImage: "/og/main.png",
63
+ twitterCreator: "@example",
64
+ });
65
+
66
+ // src/routes/about.tsx
67
+ export const Route = createFileRoute("/about")({
68
+ head: () => pageHead({ title: "About", description: "Who we are.", path: "/about" }),
69
+ component: About,
70
+ });
71
+ ```
72
+
73
+ It returns the title, description, canonical link, Open Graph tags and Twitter tags. `type: "article"` with `published` and `modified` adds the article dates. `noindex: true` adds a robots tag.
74
+
75
+ Two tags with the same name, like the light and dark `theme-color`, can't go through `head()`, because the router keeps only one. Write them straight into the root document.
76
+
77
+ ## Workers bindings
78
+
79
+ `workers-start/workers` reaches `cloudflare:workers` lazily, so the same module works in the Worker, in vitest and in the client bundle.
80
+
81
+ ```ts
82
+ import { afterResponse, getBinding, getEnvString, isKvNamespace } from "workers-start/workers";
83
+
84
+ const kv = await getBinding("CACHE_KV", isKvNamespace); // null outside workerd
85
+ const key = await getEnvString("API_KEY"); // Worker env, then process.env
86
+ await afterResponse(refreshCache()); // waitUntil in workerd, awaited elsewhere
87
+ ```
88
+
89
+ In tests, `setWorkersModule({ env, waitUntil })` stands in for the runtime.
90
+
91
+ ## Inline scripts
92
+
93
+ `workers-start/scripts` returns strings for `dangerouslySetInnerHTML` in the root document.
94
+
95
+ - `themeScript()` applies a stored `light` or `dark` choice before first paint. With nothing stored it does nothing, and `color-scheme: light dark` follows the OS.
96
+ - `analyticsScript({ measurementId, hosts })` loads GA4 only on the listed hostnames, so local dev and preview deploys never report.
97
+
98
+ ## Secret check
99
+
100
+ Run it between the build and the deploy:
101
+
102
+ ```json
103
+ "deploy": "vite build && workers-start-check-bundle && wrangler deploy"
104
+ ```
105
+
106
+ It reads every value in your local `.env*` and `.dev.vars*` files and fails if any of them appears in a built file. It skips `dist/server/.dev.vars`, which wrangler never uploads. Flags: `--dist <dir>` (default `dist`; `out` for a static site), `--root <dir>`, `--skip <filename>`.
107
+
108
+ ## Biome preset
109
+
110
+ ```jsonc
111
+ // biome.jsonc
112
+ { "extends": ["workers-start/biome"] }
113
+ ```
114
+
115
+ Biome's recommended rules, Tailwind directives in CSS, sorted imports and JSX attributes, and file-name rules off under `src/routes`, where names like `$slug.tsx` and `robots[.]txt.ts` are routing syntax.
116
+
117
+ ## License
118
+
119
+ MIT
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.6.8/schema.json",
3
+ "formatter": { "indentStyle": "space", "indentWidth": 2, "lineEnding": "lf", "lineWidth": 80 },
4
+ "javascript": {
5
+ "formatter": {
6
+ "arrowParentheses": "always",
7
+ "jsxQuoteStyle": "double",
8
+ "quoteProperties": "asNeeded",
9
+ "semicolons": "always",
10
+ "trailingCommas": "es5"
11
+ }
12
+ },
13
+ "json": { "formatter": { "trailingCommas": "none" } },
14
+ "css": { "parser": { "tailwindDirectives": true } },
15
+ "assist": { "actions": { "source": { "organizeImports": "on", "useSortedAttributes": "on" } } },
16
+ "linter": {
17
+ "rules": {
18
+ "preset": "recommended",
19
+ "security": { "noDangerouslySetInnerHtml": "off" },
20
+ "performance": { "useTopLevelRegex": "error" }
21
+ }
22
+ },
23
+ "overrides": [
24
+ {
25
+ "includes": ["**/src/routes/**"],
26
+ "linter": { "rules": { "style": { "useFilenamingConvention": "off" } } }
27
+ }
28
+ ]
29
+ }
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * workers-start-check-bundle [--dist dist] [--root .] [--skip name ...]
4
+ *
5
+ * Exits 1 if any local env value appears in a built file. Run it between the
6
+ * build and the deploy.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=check-bundle-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-bundle-cli.d.ts","sourceRoot":"","sources":["../src/check-bundle-cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG"}
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * workers-start-check-bundle [--dist dist] [--root .] [--skip name ...]
4
+ *
5
+ * Exits 1 if any local env value appears in a built file. Run it between the
6
+ * build and the deploy.
7
+ */
8
+ import { relative, resolve } from "node:path";
9
+ import { checkBundle, DEFAULT_SKIP } from "./check-bundle.js";
10
+ function parseArgs(argv) {
11
+ let dist = "dist";
12
+ let root = ".";
13
+ const skip = [...DEFAULT_SKIP];
14
+ for (let i = 0; i < argv.length; i++) {
15
+ const flag = argv[i];
16
+ const value = argv[i + 1];
17
+ if ((flag === "--dist" || flag === "--root" || flag === "--skip") && value === undefined) {
18
+ throw new Error(`${flag} needs a value`);
19
+ }
20
+ if (flag === "--dist") {
21
+ dist = value;
22
+ i++;
23
+ }
24
+ else if (flag === "--root") {
25
+ root = value;
26
+ i++;
27
+ }
28
+ else if (flag === "--skip") {
29
+ skip.push(value);
30
+ i++;
31
+ }
32
+ else {
33
+ throw new Error(`Unknown argument: ${flag}`);
34
+ }
35
+ }
36
+ return { dist, root, skip };
37
+ }
38
+ function main() {
39
+ const args = parseArgs(process.argv.slice(2));
40
+ const root = resolve(args.root);
41
+ const dist = resolve(root, args.dist);
42
+ const result = checkBundle(root, dist, args.skip);
43
+ if (result.leaked.length === 0) {
44
+ console.log(` ok none of ${result.envValues} local env value(s) appear in ${result.files} built file(s)`);
45
+ return;
46
+ }
47
+ console.error(`\nRefusing to ship: the build contains the value of ${result.leaked.length} local secret(s):\n`);
48
+ for (const key of result.leaked) {
49
+ console.error(` ${key}`);
50
+ }
51
+ console.error(`\n Find where it is read at build time (import.meta.env, define, a module-scope\n process.env read) under ${relative(process.cwd(), dist) || "."}/ and fix that.\n`);
52
+ process.exit(1);
53
+ }
54
+ try {
55
+ main();
56
+ }
57
+ catch (error) {
58
+ console.error(`\n ${error instanceof Error ? error.message : String(error)}\n`);
59
+ process.exit(1);
60
+ }
61
+ //# sourceMappingURL=check-bundle-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-bundle-cli.js","sourceRoot":"","sources":["../src/check-bundle-cli.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE9D,SAAS,SAAS,CAAC,IAAc;IAC/B,IAAI,IAAI,GAAG,MAAM,CAAC;IAClB,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,MAAM,IAAI,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC;IAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,CAA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,MAAM,qBAAqB,CAAC,CAAC;IAChH,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,CAAC,KAAK,CACX,+GAA+G,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CACvK,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,IAAI,CAAC;IACH,IAAI,EAAE,CAAC;AACT,CAAC;AAAC,OAAO,KAAK,EAAE,CAAC;IACf,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Finds local secrets compiled into a build.
3
+ *
4
+ * Reads every value in the local `.env*` and `.dev.vars*` files (examples
5
+ * excluded) and searches the built files for each one. A match means a key
6
+ * reached something that ships, whichever tool put it there.
7
+ */
8
+ /** Values shorter than this are flags or placeholders, not secrets. */
9
+ export declare const MIN_SECRET_LENGTH = 12;
10
+ /** `.dev.vars` copies the Cloudflare Vite plugin writes for `vite preview`; wrangler never uploads them. */
11
+ export declare const DEFAULT_SKIP: string[];
12
+ /** KEY=value pairs from a dotenv-style file, quotes stripped. */
13
+ export declare function parseEnvFile(source: string): [string, string][];
14
+ /** The env keys whose values appear in any of the given file contents. */
15
+ export declare function leakedKeys(pairs: [string, string][], contents: string[]): string[];
16
+ /** Every KEY=value pair in the local env files of `dir`. */
17
+ export declare function localEnvPairs(dir: string): [string, string][];
18
+ /** Every file under `dir`, recursively, minus names in `skip`. */
19
+ export declare function listFiles(dir: string, skip?: readonly string[]): string[];
20
+ export interface CheckResult {
21
+ envValues: number;
22
+ files: number;
23
+ leaked: string[];
24
+ }
25
+ export declare function checkBundle(root: string, dist: string, skip?: readonly string[]): CheckResult;
26
+ //# sourceMappingURL=check-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-bundle.d.ts","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,uEAAuE;AACvE,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAOpC,4GAA4G;AAC5G,eAAO,MAAM,YAAY,UAAgB,CAAC;AAE1C,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAU/D;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQlF;AAED,4DAA4D;AAC5D,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAI7D;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAE,SAAS,MAAM,EAAiB,GAAG,MAAM,EAAE,CAWvF;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,SAAS,MAAM,EAAiB,GAAG,WAAW,CAW3G"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Finds local secrets compiled into a build.
3
+ *
4
+ * Reads every value in the local `.env*` and `.dev.vars*` files (examples
5
+ * excluded) and searches the built files for each one. A match means a key
6
+ * reached something that ships, whichever tool put it there.
7
+ */
8
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
9
+ import { join } from "node:path";
10
+ /** Values shorter than this are flags or placeholders, not secrets. */
11
+ export const MIN_SECRET_LENGTH = 12;
12
+ const ENV_FILE = /^(\.env(\..+)?|\.dev\.vars(\..+)?)$/;
13
+ const EXAMPLE_FILE = /\.example$/;
14
+ const ENV_LINE = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/;
15
+ const QUOTED = /^(['"])(.*)\1$/;
16
+ /** `.dev.vars` copies the Cloudflare Vite plugin writes for `vite preview`; wrangler never uploads them. */
17
+ export const DEFAULT_SKIP = [".dev.vars"];
18
+ /** KEY=value pairs from a dotenv-style file, quotes stripped. */
19
+ export function parseEnvFile(source) {
20
+ const pairs = [];
21
+ for (const line of source.split("\n")) {
22
+ const match = line.match(ENV_LINE);
23
+ if (!(match?.[1] && match[2] !== undefined)) {
24
+ continue;
25
+ }
26
+ pairs.push([match[1], match[2].replace(QUOTED, "$2")]);
27
+ }
28
+ return pairs;
29
+ }
30
+ /** The env keys whose values appear in any of the given file contents. */
31
+ export function leakedKeys(pairs, contents) {
32
+ const leaked = new Set();
33
+ for (const [key, value] of pairs) {
34
+ if (value.length >= MIN_SECRET_LENGTH && contents.some((text) => text.includes(value))) {
35
+ leaked.add(key);
36
+ }
37
+ }
38
+ return [...leaked].sort();
39
+ }
40
+ /** Every KEY=value pair in the local env files of `dir`. */
41
+ export function localEnvPairs(dir) {
42
+ return readdirSync(dir)
43
+ .filter((name) => ENV_FILE.test(name) && !EXAMPLE_FILE.test(name))
44
+ .flatMap((name) => parseEnvFile(readFileSync(join(dir, name), "utf8")));
45
+ }
46
+ /** Every file under `dir`, recursively, minus names in `skip`. */
47
+ export function listFiles(dir, skip = DEFAULT_SKIP) {
48
+ const files = [];
49
+ for (const name of readdirSync(dir)) {
50
+ const path = join(dir, name);
51
+ if (statSync(path).isDirectory()) {
52
+ files.push(...listFiles(path, skip));
53
+ }
54
+ else if (!skip.includes(name)) {
55
+ files.push(path);
56
+ }
57
+ }
58
+ return files;
59
+ }
60
+ export function checkBundle(root, dist, skip = DEFAULT_SKIP) {
61
+ if (!existsSync(dist)) {
62
+ throw new Error(`${dist} does not exist. Build first.`);
63
+ }
64
+ const pairs = localEnvPairs(root);
65
+ const files = listFiles(dist, skip);
66
+ const leaked = leakedKeys(pairs, files.map((path) => readFileSync(path, "latin1")));
67
+ return { envValues: pairs.length, files: files.length, leaked };
68
+ }
69
+ //# sourceMappingURL=check-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-bundle.js","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,uEAAuE;AACvE,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEpC,MAAM,QAAQ,GAAG,qCAAqC,CAAC;AACvD,MAAM,YAAY,GAAG,YAAY,CAAC;AAClC,MAAM,QAAQ,GAAG,4DAA4D,CAAC;AAC9E,MAAM,MAAM,GAAG,gBAAgB,CAAC;AAEhC,4GAA4G;AAC5G,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,WAAW,CAAC,CAAC;AAE1C,iEAAiE;AACjE,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,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E,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;YACjC,KAAK,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;QACvC,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAChC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAQD,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,IAAY,EAAE,IAAI,GAAsB,YAAY;IAC5F,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAC;IAC1D,CAAC;IACD,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACpC,MAAM,MAAM,GAAG,UAAU,CACvB,KAAK,EACL,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAClD,CAAC;IACF,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;AAClE,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * A Worker entry that sits in front of a TanStack Start handler (or any
3
+ * `{ fetch }` handler) and fixes what Start leaves to the app:
4
+ *
5
+ * - A page request whose Accept header includes text/markdown gets the
6
+ * Markdown rendering the app provides, on the same URL.
7
+ * - A page request whose Accept header names neither text/html nor *∕* gets
8
+ * HTML instead of Start's 406.
9
+ * - Page responses of both kinds carry `Vary: Accept`.
10
+ * - Paths under a read-only prefix (default `/api/`) answer any method other
11
+ * than GET and HEAD with 405, instead of an empty 200 page shell.
12
+ */
13
+ type MaybePromise<T> = T | Promise<T>;
14
+ /** What a Markdown renderer returns: a body, a body with a status, or null to serve HTML. */
15
+ export type MarkdownResult = string | {
16
+ body: string;
17
+ status?: number;
18
+ } | null | undefined;
19
+ export interface FetchHandler {
20
+ fetch(request: Request, ...rest: any[]): MaybePromise<Response>;
21
+ }
22
+ export interface EntryOptions {
23
+ /** The framework handler, usually the default export of `@tanstack/react-start/server-entry`. */
24
+ handler: FetchHandler;
25
+ /**
26
+ * Markdown rendering of a page. Called for GET and HEAD page requests whose
27
+ * Accept header includes text/markdown. Return null to serve HTML instead.
28
+ */
29
+ markdown?: (pathname: string, request: Request) => MaybePromise<MarkdownResult>;
30
+ /** Path prefixes that only accept GET and HEAD. Default `["/api/"]`. Pass `[]` to turn off. */
31
+ readOnlyPrefixes?: string[];
32
+ /**
33
+ * Whether a path is a page (negotiated and given `Vary: Accept`). Default:
34
+ * not under a read-only prefix, not a framework internal (`/_…`, `/@…`), and
35
+ * no file extension on the last segment.
36
+ */
37
+ isPage?: (pathname: string) => boolean;
38
+ }
39
+ export declare const MARKDOWN_HEADERS: Readonly<Record<string, string>>;
40
+ export declare function wantsMarkdown(request: Request): boolean;
41
+ export declare function defaultIsPage(pathname: string, readOnlyPrefixes?: readonly string[]): boolean;
42
+ /** `/learn/` becomes `/learn`; `/` stays `/`. */
43
+ export declare function normalizePath(pathname: string): string;
44
+ export declare function createEntry(options: EntryOptions): {
45
+ fetch(request: Request, ...rest: unknown[]): Promise<Response>;
46
+ };
47
+ export {};
48
+ //# sourceMappingURL=entry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"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,CAAC,QAAQ,CAAC,CAAC;CAChE,CAkCA"}
package/dist/entry.js ADDED
@@ -0,0 +1,79 @@
1
+ /**
2
+ * A Worker entry that sits in front of a TanStack Start handler (or any
3
+ * `{ fetch }` handler) and fixes what Start leaves to the app:
4
+ *
5
+ * - A page request whose Accept header includes text/markdown gets the
6
+ * Markdown rendering the app provides, on the same URL.
7
+ * - A page request whose Accept header names neither text/html nor *∕* gets
8
+ * HTML instead of Start's 406.
9
+ * - Page responses of both kinds carry `Vary: Accept`.
10
+ * - Paths under a read-only prefix (default `/api/`) answer any method other
11
+ * than GET and HEAD with 405, instead of an empty 200 page shell.
12
+ */
13
+ const ACCEPTS_HTML = /(^|,)\s*(\*\/\*|text\/html)/;
14
+ const TRAILING_SLASHES = /\/+$/;
15
+ export const MARKDOWN_HEADERS = {
16
+ "content-type": "text/markdown; charset=utf-8",
17
+ vary: "Accept",
18
+ // A Markdown body is a second representation of a page, not a page of its own.
19
+ "x-robots-tag": "noindex",
20
+ };
21
+ export function wantsMarkdown(request) {
22
+ return (request.headers.get("accept") ?? "").includes("text/markdown");
23
+ }
24
+ export function defaultIsPage(pathname, readOnlyPrefixes = ["/api/"]) {
25
+ if (readOnlyPrefixes.some((prefix) => pathname.startsWith(prefix))) {
26
+ return false;
27
+ }
28
+ if (pathname.startsWith("/_") || pathname.startsWith("/@")) {
29
+ return false;
30
+ }
31
+ const lastSegment = pathname.slice(pathname.lastIndexOf("/") + 1);
32
+ return !lastSegment.includes(".");
33
+ }
34
+ /** `/learn/` becomes `/learn`; `/` stays `/`. */
35
+ export function normalizePath(pathname) {
36
+ return pathname.length > 1 ? pathname.replace(TRAILING_SLASHES, "") || "/" : pathname;
37
+ }
38
+ function markdownResponse(result, head) {
39
+ const { body, status = 200 } = typeof result === "string" ? { body: result } : result;
40
+ return new Response(head ? null : body, { status, headers: MARKDOWN_HEADERS });
41
+ }
42
+ function withVaryAccept(response) {
43
+ if (!response.headers.get("content-type")?.startsWith("text/html")) {
44
+ return response;
45
+ }
46
+ const headers = new Headers(response.headers);
47
+ headers.append("vary", "Accept");
48
+ return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
49
+ }
50
+ export function createEntry(options) {
51
+ const readOnlyPrefixes = options.readOnlyPrefixes ?? ["/api/"];
52
+ const isPage = options.isPage ?? ((pathname) => defaultIsPage(pathname, readOnlyPrefixes));
53
+ return {
54
+ async fetch(request, ...rest) {
55
+ const { pathname } = new URL(request.url);
56
+ const isRead = request.method === "GET" || request.method === "HEAD";
57
+ if (!isRead && readOnlyPrefixes.some((prefix) => pathname.startsWith(prefix))) {
58
+ return Response.json({ error: "Method not allowed" }, { status: 405, headers: { allow: "GET, HEAD" } });
59
+ }
60
+ if (!isPage(pathname)) {
61
+ return options.handler.fetch(request, ...rest);
62
+ }
63
+ if (isRead && options.markdown && wantsMarkdown(request)) {
64
+ const result = await options.markdown(normalizePath(pathname), request);
65
+ if (result !== null && result !== undefined) {
66
+ return markdownResponse(result, request.method === "HEAD");
67
+ }
68
+ }
69
+ let pageRequest = request;
70
+ if (isRead && !ACCEPTS_HTML.test(request.headers.get("accept") ?? "*/*")) {
71
+ const headers = new Headers(request.headers);
72
+ headers.set("accept", "text/html");
73
+ pageRequest = new Request(request, { headers });
74
+ }
75
+ return withVaryAccept(await options.handler.fetch(pageRequest, ...rest));
76
+ },
77
+ };
78
+ }
79
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AA8BH,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEhC,MAAM,CAAC,MAAM,gBAAgB,GAAqC;IAChE,cAAc,EAAE,8BAA8B;IAC9C,IAAI,EAAE,QAAQ;IACd,+EAA+E;IAC/E,cAAc,EAAE,SAAS;CAC1B,CAAC;AAEF,MAAM,UAAU,aAAa,CAAC,OAAgB;I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+ /**
2
+ * Per-page head tags in the shape a TanStack Router `head()` returns.
3
+ *
4
+ * The router keeps one meta per `name` or `property`, deepest route winning,
5
+ * so any tag a page leaves out falls back to a parent's. This helper writes
6
+ * the full Open Graph and Twitter set for every page so nothing inherits the
7
+ * homepage's share card by accident.
8
+ */
9
+ export interface SiteHead {
10
+ /** Absolute origin, no trailing slash: `https://example.com`. */
11
+ url: string;
12
+ /** Used for `og:site_name` and the default title suffix. */
13
+ name: string;
14
+ /** Path under the site of the default share image. */
15
+ defaultImage?: string;
16
+ /** Twitter handle with the @. */
17
+ twitterCreator?: string;
18
+ /** Default `en_US`. */
19
+ locale?: string;
20
+ /** Default `(title) => \`${title} | ${name}\``. */
21
+ titleTemplate?: (title: string) => string;
22
+ }
23
+ export interface PageSeo {
24
+ title: string;
25
+ /** Use `title` as the whole document title, without the template. */
26
+ rawTitle?: boolean;
27
+ description: string;
28
+ /** Path under the site, starting with "/". "/" is the homepage. */
29
+ path: string;
30
+ type?: "website" | "article";
31
+ /** Defaults to `title`. */
32
+ socialTitle?: string;
33
+ /** Defaults to `description`. */
34
+ socialDescription?: string;
35
+ /** Defaults to `socialDescription`. */
36
+ twitterDescription?: string;
37
+ /** Path under the site, or an absolute URL. */
38
+ image?: string;
39
+ imageSize?: {
40
+ width: number;
41
+ height: number;
42
+ alt: string;
43
+ };
44
+ /** ISO date, for articles. */
45
+ published?: string;
46
+ /** ISO date, for articles. */
47
+ modified?: string;
48
+ /** Adds `robots: noindex`. */
49
+ noindex?: boolean;
50
+ }
51
+ export type MetaTag = {
52
+ title: string;
53
+ } | {
54
+ name: string;
55
+ content: string;
56
+ } | {
57
+ property: string;
58
+ content: string;
59
+ };
60
+ export interface HeadTags {
61
+ meta: MetaTag[];
62
+ links: {
63
+ rel: string;
64
+ href: string;
65
+ }[];
66
+ }
67
+ export declare function createPageHead(site: SiteHead): {
68
+ pageHead: (seo: PageSeo) => HeadTags;
69
+ absoluteUrl: (path: string) => string;
70
+ };
71
+ //# source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