chore: worker setup for docs
This commit is contained in:
@@ -20,3 +20,5 @@ node_modules
|
|||||||
|
|
||||||
src/routeTree.gen.ts
|
src/routeTree.gen.ts
|
||||||
.source
|
.source
|
||||||
|
worker-configuration.d.ts
|
||||||
|
.react-router
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import type { AppLoadContext, EntryContext } from 'react-router';
|
||||||
|
import { ServerRouter } from 'react-router';
|
||||||
|
import { isbot } from 'isbot';
|
||||||
|
import { renderToReadableStream } from 'react-dom/server';
|
||||||
|
|
||||||
|
export default async function handleRequest(
|
||||||
|
request: Request,
|
||||||
|
responseStatusCode: number,
|
||||||
|
responseHeaders: Headers,
|
||||||
|
routerContext: EntryContext,
|
||||||
|
_loadContext: AppLoadContext
|
||||||
|
) {
|
||||||
|
let shellRendered = false;
|
||||||
|
const userAgent = request.headers.get('user-agent');
|
||||||
|
|
||||||
|
const body = await renderToReadableStream(
|
||||||
|
<ServerRouter context={routerContext} url={request.url} />,
|
||||||
|
{
|
||||||
|
onError(error: unknown) {
|
||||||
|
responseStatusCode = 500;
|
||||||
|
if (shellRendered) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
shellRendered = true;
|
||||||
|
|
||||||
|
if ((userAgent && isbot(userAgent)) || routerContext.isSpaMode) {
|
||||||
|
await body.allReady;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseHeaders.set('Content-Type', 'text/html');
|
||||||
|
return new Response(body, {
|
||||||
|
headers: responseHeaders,
|
||||||
|
status: responseStatusCode
|
||||||
|
});
|
||||||
|
}
|
||||||
+11
-6
@@ -4,16 +4,16 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "react-router dev",
|
"dev": "react-router dev",
|
||||||
"build": "react-router build",
|
"build": "react-router build",
|
||||||
"preview": "react-router-serve ./build/server/index.js",
|
"preview": "wrangler dev --port 4173",
|
||||||
"start": "react-router-serve ./build/server/index.js",
|
"start": "wrangler dev --port 3000",
|
||||||
"types:check": "fumadocs-mdx && tsc --noEmit",
|
"deploy": "pnpm run build && wrangler deploy",
|
||||||
|
"cf-typegen": "wrangler types && react-router typegen",
|
||||||
|
"types:check": "fumadocs-mdx && wrangler types && react-router typegen && tsc --noEmit",
|
||||||
"postinstall": "fumadocs-mdx"
|
"postinstall": "fumadocs-mdx"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@scalar/core": "^0.3.28",
|
"@scalar/core": "^0.3.28",
|
||||||
"@react-router/dev": "^7.9.4",
|
"@react-router/dev": "^7.9.4",
|
||||||
"@react-router/node": "^7.9.4",
|
|
||||||
"@react-router/serve": "^7.9.4",
|
|
||||||
"fumadocs-core": "16.2.1",
|
"fumadocs-core": "16.2.1",
|
||||||
"fumadocs-mdx": "14.0.4",
|
"fumadocs-mdx": "14.0.4",
|
||||||
"fumadocs-ui": "16.2.1",
|
"fumadocs-ui": "16.2.1",
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
"vite": "^7.2.0"
|
"vite": "^7.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@cloudflare/vite-plugin": "1.15.3",
|
||||||
"@tailwindcss/vite": "^4.1.16",
|
"@tailwindcss/vite": "^4.1.16",
|
||||||
"@types/mdx": "^2.0.13",
|
"@types/mdx": "^2.0.13",
|
||||||
"@types/node": "^24.10.0",
|
"@types/node": "^24.10.0",
|
||||||
@@ -34,6 +35,10 @@
|
|||||||
"@types/react-dom": "^19.2.2",
|
"@types/react-dom": "^19.2.2",
|
||||||
"tailwindcss": "^4.1.16",
|
"tailwindcss": "^4.1.16",
|
||||||
"typescript": "^5.9.3",
|
"typescript": "^5.9.3",
|
||||||
"vite-tsconfig-paths": "^5.1.4"
|
"vite-tsconfig-paths": "^5.1.4",
|
||||||
|
"wrangler": "4.86.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^20.19.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import type { Config } from '@react-router/dev/config';
|
import type { Config } from '@react-router/dev/config';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
basename: '/docs'
|
ssr: true,
|
||||||
|
basename: '/docs',
|
||||||
|
future: {
|
||||||
|
v8_viteEnvironmentApi: true
|
||||||
|
}
|
||||||
} satisfies Config;
|
} satisfies Config;
|
||||||
|
|||||||
+11
-1
@@ -1,5 +1,14 @@
|
|||||||
{
|
{
|
||||||
"include": ["app/**/*.ts", "app/**/*.tsx", "react-router.config.ts", "source.config.ts", "vite.config.ts"],
|
"include": [
|
||||||
|
".react-router/types/**/*",
|
||||||
|
"app/**/*.ts",
|
||||||
|
"app/**/*.tsx",
|
||||||
|
"workers/**/*.ts",
|
||||||
|
"worker-configuration.d.ts",
|
||||||
|
"react-router.config.ts",
|
||||||
|
"source.config.ts",
|
||||||
|
"vite.config.ts"
|
||||||
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
@@ -15,6 +24,7 @@
|
|||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
|
"rootDirs": [".", "./.react-router/types"],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./app/*"],
|
"@/*": ["./app/*"],
|
||||||
"fumadocs-mdx:collections/*": [".source/*"]
|
"fumadocs-mdx:collections/*": [".source/*"]
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import mdx from 'fumadocs-mdx/vite';
|
import mdx from 'fumadocs-mdx/vite';
|
||||||
import { reactRouter } from '@react-router/dev/vite';
|
import { reactRouter } from '@react-router/dev/vite';
|
||||||
|
import { cloudflare } from '@cloudflare/vite-plugin';
|
||||||
import tailwindcss from '@tailwindcss/vite';
|
import tailwindcss from '@tailwindcss/vite';
|
||||||
import tsConfigPaths from 'vite-tsconfig-paths';
|
import tsConfigPaths from 'vite-tsconfig-paths';
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
base: '/docs',
|
base: '/docs',
|
||||||
plugins: [
|
plugins: [
|
||||||
|
cloudflare({ viteEnvironment: { name: 'ssr' } }),
|
||||||
mdx(await import('./source.config')),
|
mdx(await import('./source.config')),
|
||||||
tailwindcss(),
|
tailwindcss(),
|
||||||
tsConfigPaths({
|
tsConfigPaths({
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { createRequestHandler } from 'react-router';
|
||||||
|
|
||||||
|
declare module 'react-router' {
|
||||||
|
export interface AppLoadContext {
|
||||||
|
cloudflare: {
|
||||||
|
env: Env;
|
||||||
|
ctx: ExecutionContext;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestHandler = createRequestHandler(
|
||||||
|
() => import('virtual:react-router/server-build'),
|
||||||
|
import.meta.env.MODE
|
||||||
|
);
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fetch(request, env, ctx) {
|
||||||
|
return requestHandler(request, {
|
||||||
|
cloudflare: { env, ctx }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} satisfies ExportedHandler<Env>;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"$schema": "node_modules/wrangler/config-schema.json",
|
||||||
|
"name": "cio-docs",
|
||||||
|
"main": "./workers/app.ts",
|
||||||
|
"compatibility_date": "2026-03-13",
|
||||||
|
"compatibility_flags": ["nodejs_compat"],
|
||||||
|
"assets": {
|
||||||
|
"binding": "ASSETS",
|
||||||
|
"directory": "./build/client"
|
||||||
|
},
|
||||||
|
"observability": {
|
||||||
|
"logs": {
|
||||||
|
"enabled": true,
|
||||||
|
"invocation_logs": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+965
-70
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user