eddev 2.0.0-beta.12 → 2.0.0-beta.121
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/css/editor-styles.css +4 -0
- package/dist/app/entry/HydrationOverlay.d.ts +1 -0
- package/dist/app/entry/HydrationOverlay.js +2 -0
- package/dist/app/entry/MetaTags.d.ts +7 -0
- package/dist/app/entry/MetaTags.js +17 -0
- package/dist/app/entry/boot-admin.js +9 -3
- package/dist/app/entry/hydration-script.d.ts +1 -0
- package/dist/app/entry/hydration-script.js +18 -0
- package/dist/app/entry/spa-root.js +3 -5
- package/dist/app/entry/ssr-root-client.d.ts +3 -1
- package/dist/app/entry/ssr-root-client.js +18 -6
- package/dist/app/entry/ssr-root.d.ts +3 -4
- package/dist/app/entry/ssr-root.js +19 -19
- package/dist/app/lib/admin/index.d.ts +2 -2
- package/dist/app/lib/admin/index.js +2 -2
- package/dist/app/lib/admin/installFieldTypes.js +3 -1
- package/dist/app/lib/admin/runWidgets.js +1 -1
- package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
- package/dist/app/lib/blocks/ContentBlocks.js +5 -5
- package/dist/app/lib/blocks/EditableText.d.ts +15 -2
- package/dist/app/lib/blocks/EditableText.js +10 -4
- package/dist/app/lib/blocks/InnerBlocks.d.ts +21 -7
- package/dist/app/lib/blocks/InnerBlocks.js +75 -28
- package/dist/app/lib/blocks/block-utils.d.ts +2 -2
- package/dist/app/lib/blocks/block-utils.js +2 -2
- package/dist/app/lib/blocks/defineBlock.d.ts +3 -0
- package/dist/app/lib/blocks/defineBlock.js +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.js +164 -0
- package/dist/app/lib/blocks/editor/EditorSupport.js +17 -12
- package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
- package/dist/app/lib/blocks/editor/block-templates.d.ts +6 -0
- package/dist/app/lib/blocks/editor/block-templates.js +64 -0
- package/dist/app/lib/blocks/editor/create-block.d.ts +9 -0
- package/dist/app/lib/blocks/editor/create-block.js +13 -0
- package/dist/app/lib/blocks/editor/editor-config.d.ts +70 -7
- package/dist/app/lib/blocks/editor/editor-config.js +29 -62
- package/dist/app/lib/blocks/editor/installGutenbergHooks.d.ts +3 -0
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +105 -16
- package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
- package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
- package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
- package/dist/app/lib/blocks/index.d.ts +10 -9
- package/dist/app/lib/blocks/index.js +10 -9
- package/dist/app/lib/blocks/inline-editing.d.ts +9 -1
- package/dist/app/lib/blocks/inline-editing.js +7 -5
- package/dist/app/lib/devtools/components/BreakpointIndicator.js +1 -1
- package/dist/app/lib/devtools/components/DevUI.js +4 -3
- package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
- package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
- package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
- package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
- package/dist/app/lib/devtools/hooks/useTailwind.d.ts +2305 -1261
- package/dist/app/lib/devtools/hooks/useTailwind.js +1 -1
- package/dist/app/lib/devtools/index.d.ts +1 -1
- package/dist/app/lib/devtools/index.js +1 -1
- package/dist/app/lib/devtools/loader.js +8 -7
- package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
- package/dist/app/lib/devtools/useQueryDebug.js +5 -8
- package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
- package/dist/app/lib/dynamic/dynamic.js +5 -1
- package/dist/app/lib/dynamic/index.d.ts +1 -1
- package/dist/app/lib/dynamic/index.js +1 -1
- package/dist/app/lib/hooks/index.d.ts +4 -5
- package/dist/app/lib/hooks/index.js +4 -5
- package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
- package/dist/app/lib/hooks/queryUtils.js +66 -26
- package/dist/app/lib/hooks/useAppData.js +12 -1
- package/dist/app/lib/hooks/useRPC.d.ts +0 -4
- package/dist/app/lib/hooks/useRPC.js +1 -8
- package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
- package/dist/app/lib/internal/finalize-rpc.js +3 -0
- package/dist/app/lib/internal/index.d.ts +5 -4
- package/dist/app/lib/internal/index.js +5 -4
- package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
- package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
- package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/index.js +1 -1
- package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
- package/dist/app/lib/routing/components/BackButton.js +47 -0
- package/dist/app/lib/routing/components/BrowserRouter.d.ts +5 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +98 -19
- package/dist/app/lib/routing/components/ClientOnly.d.ts +1 -1
- package/dist/app/lib/routing/components/ClientOnly.js +2 -2
- package/dist/app/lib/routing/components/Link.d.ts +1 -0
- package/dist/app/lib/routing/components/Link.js +11 -12
- package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
- package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
- package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
- package/dist/app/lib/routing/components/SSRRouter.js +5 -6
- package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
- package/dist/app/lib/routing/context.d.ts +8 -5
- package/dist/app/lib/routing/context.js +13 -96
- package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
- package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
- package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
- package/dist/app/lib/routing/hooks/useRoute.js +22 -1
- package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
- package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
- package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
- package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouter.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
- package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
- package/dist/app/lib/routing/index.d.ts +14 -13
- package/dist/app/lib/routing/index.js +14 -13
- package/dist/app/lib/routing/loader.d.ts +2 -2
- package/dist/app/lib/routing/loader.js +20 -11
- package/dist/app/lib/routing/types.d.ts +37 -10
- package/dist/app/lib/routing/utils.d.ts +5 -2
- package/dist/app/lib/routing/utils.js +37 -4
- package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
- package/dist/app/lib/runtime/apiConfig.js +6 -0
- package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
- package/dist/app/lib/runtime/errorHandling.js +6 -0
- package/dist/app/lib/runtime/index.d.ts +2 -0
- package/dist/app/lib/runtime/index.js +2 -0
- package/dist/app/lib/views/index.d.ts +1 -1
- package/dist/app/lib/views/index.js +1 -1
- package/dist/app/server/defineRouter.d.ts +2 -0
- package/dist/app/server/defineRouter.js +4 -0
- package/dist/app/server/index.d.ts +5 -3
- package/dist/app/server/index.js +5 -3
- package/dist/app/server/proxy-wp-admin.d.ts +1 -2
- package/dist/app/server/proxy-wp-admin.js +41 -14
- package/dist/app/server/render-ssr-page.d.ts +27 -2
- package/dist/app/server/render-ssr-page.js +192 -12
- package/dist/app/server/rpc.d.ts +56 -0
- package/dist/app/server/rpc.js +18 -0
- package/dist/app/server/server-context.d.ts +44 -4
- package/dist/app/server/server-context.js +305 -28
- package/dist/app/server/utils/replace-host.d.ts +1 -1
- package/dist/app/server/utils/replace-host.js +10 -2
- package/dist/app/server/utils/swr-cache.d.ts +4 -0
- package/dist/app/server/utils/swr-cache.js +31 -0
- package/dist/app/utils/APIProvider.d.ts +2 -0
- package/dist/app/utils/APIProvider.js +5 -0
- package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
- package/dist/app/utils/BlockErrorBoundary.js +38 -0
- package/dist/app/utils/ErrorMessage.d.ts +5 -0
- package/dist/app/utils/ErrorMessage.js +14 -0
- package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
- package/dist/app/utils/RouteErrorBoundary.js +38 -0
- package/dist/app/utils/asset-capture.d.ts +2 -0
- package/dist/app/utils/asset-capture.js +5 -0
- package/dist/app/utils/hydration-debugger.d.ts +13 -0
- package/dist/app/utils/hydration-debugger.js +11 -0
- package/dist/app/utils/query-client.d.ts +2 -0
- package/dist/app/utils/query-client.js +5 -1
- package/dist/app/utils/query-monitor.d.ts +26 -0
- package/dist/app/utils/query-monitor.js +7 -0
- package/dist/app/utils/trpc-client.d.ts +2 -0
- package/dist/app/utils/trpc-client.js +39 -0
- package/dist/node/cli/cli-worker.js +10 -5
- package/dist/node/cli/cli.js +81 -11
- package/dist/node/cli/display/CLIApp.js +3 -6
- package/dist/node/cli/display/boot-cli-app.js +1 -1
- package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
- package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
- package/dist/node/cli/display/tools/cli-tools.js +9 -9
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/build-vinxi.js +2 -1
- package/dist/node/compiler/bundler.admin.d.ts +1 -1
- package/dist/node/compiler/bundler.admin.js +1 -1
- package/dist/node/compiler/bundler.frontend.js +1 -1
- package/dist/node/compiler/dev-server.js +10 -0
- package/dist/node/compiler/get-vite-config.d.ts +7 -1
- package/dist/node/compiler/get-vite-config.js +96 -16
- package/dist/node/compiler/vinxi-app.d.ts +12 -0
- package/dist/node/compiler/vinxi-app.js +139 -32
- package/dist/node/compiler/vinxi-codegen.js +345 -112
- package/dist/node/graphql/graphql-codegen.d.ts +11 -1
- package/dist/node/graphql/graphql-codegen.js +210 -33
- package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
- package/dist/node/graphql/graphql-schema-loader.js +5 -16
- package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
- package/dist/node/graphql/query-files-loader.d.ts +3 -0
- package/dist/node/graphql/query-files-loader.js +5 -0
- package/dist/node/project/config.d.ts +159 -73
- package/dist/node/project/config.js +69 -20
- package/dist/node/project/env.d.ts +4 -0
- package/dist/node/project/env.js +1 -0
- package/dist/node/project/manifest/block-manifest.js +2 -1
- package/dist/node/project/manifest/manifest.d.ts +1 -0
- package/dist/node/project/manifest/manifest.js +14 -10
- package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
- package/dist/node/project/manifest/routes-manifest.js +74 -0
- package/dist/node/project/manifest/view-manifest.js +1 -1
- package/dist/node/project/project.d.ts +11 -1
- package/dist/node/project/project.js +61 -7
- package/dist/node/project/wp-info.d.ts +1 -0
- package/dist/node/project/wp-info.js +13 -1
- package/dist/node/storybook/index.d.ts +2 -0
- package/dist/node/storybook/index.js +13 -0
- package/dist/node/types/block-type.d.ts +25 -20
- package/dist/node/types/block-type.js +1 -0
- package/dist/node/types/view-type.d.ts +7 -7
- package/dist/node/utils/fetch-wp.d.ts +1 -0
- package/dist/node/utils/fetch-wp.js +27 -0
- package/dist/node/utils/fs-codegen.d.ts +2 -0
- package/dist/node/utils/fs-codegen.js +2 -1
- package/dist/node/utils/is-deploying.js +1 -1
- package/dist/node/utils/report-builder.d.ts +6 -6
- package/dist/node/utils/self-signed-cert.d.ts +2 -0
- package/dist/node/utils/self-signed-cert.js +10 -2
- package/dist/node/utils/stateful-log.js +2 -0
- package/dist/node/utils/watch-file-tree.d.ts +17 -3
- package/dist/node/utils/watch-file-tree.js +12 -5
- package/package.json +21 -12
- package/types.app.d.ts +4 -2
- package/types.app.internal.d.ts +2 -2
- package/types.meta.d.ts +105 -0
- package/types.node.d.ts +3 -3
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
- package/dist/app/lib/hooks/apiConfig.js +0 -4
- package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
- package/dist/app/lib/hooks/usePageLoad.js +0 -5
|
@@ -1,22 +1,46 @@
|
|
|
1
1
|
/// <reference types="vinxi/types/server" />
|
|
2
2
|
import { splitSetCookieString } from "cookie-es";
|
|
3
3
|
import { getProxyRequestHeaders, getRequestURL, getWebRequest } from "vinxi/http";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { ServerContext } from "./server-context.js";
|
|
5
|
+
import { renderErrorPage } from "./render-ssr-page.js";
|
|
6
|
+
export async function proxyWpAdmin(event) {
|
|
7
|
+
const serverContext = ServerContext.main;
|
|
7
8
|
const req = getWebRequest(event);
|
|
8
|
-
const
|
|
9
|
+
const reqUrl = getRequestURL(event);
|
|
10
|
+
const serverlessConfig = serverContext.config.serverless;
|
|
11
|
+
if (!serverContext.dev) {
|
|
12
|
+
if (reqUrl.pathname.toLowerCase().match(/\/+(graphql|xmlrpc|index\.php|wp\-(admin|login|json))/)) {
|
|
13
|
+
if (serverlessConfig.admin === "hide") {
|
|
14
|
+
return renderErrorPage({
|
|
15
|
+
code: 404,
|
|
16
|
+
pathname: reqUrl.pathname,
|
|
17
|
+
title: "Not Found",
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const proxyUrl = serverContext.getOriginUrl(reqUrl.href);
|
|
9
23
|
// Prepare request headers to be sent to the origin server
|
|
10
24
|
const proxyHeaders = getProxyRequestHeaders(event);
|
|
11
25
|
proxyHeaders["X-ED-Dev-Proxy"] = "true";
|
|
26
|
+
const followRedirects = !reqUrl.pathname.match(/\.[a-z0-9]$/) && !reqUrl.pathname.match(/(^\/wp-|\.php$)/);
|
|
12
27
|
// Forward the request to the origin server
|
|
28
|
+
// console.log("Proxying request", proxyUrl, {
|
|
29
|
+
// method: req.method,
|
|
30
|
+
// referrer: req.referrer,
|
|
31
|
+
// referrerPolicy: req.referrerPolicy,
|
|
32
|
+
// headers: proxyHeaders,
|
|
33
|
+
// // body: req.method.match(/get|head|options/i) ? undefined : await req.blob(),
|
|
34
|
+
// redirect: followRedirects ? "follow" : "manual",
|
|
35
|
+
// cache: "no-cache",
|
|
36
|
+
// })
|
|
13
37
|
const response = await fetch(proxyUrl, {
|
|
14
38
|
method: req.method,
|
|
15
39
|
referrer: req.referrer,
|
|
16
40
|
referrerPolicy: req.referrerPolicy,
|
|
17
41
|
headers: proxyHeaders,
|
|
18
42
|
body: req.method.match(/get|head|options/i) ? undefined : await req.blob(),
|
|
19
|
-
redirect: "manual",
|
|
43
|
+
redirect: followRedirects ? "follow" : "manual",
|
|
20
44
|
cache: "no-cache",
|
|
21
45
|
});
|
|
22
46
|
const contentType = response.headers.get("content-type");
|
|
@@ -31,8 +55,8 @@ export async function proxyWpAdmin(event, serverContext) {
|
|
|
31
55
|
cookies.push(...splitSetCookieString(value));
|
|
32
56
|
return;
|
|
33
57
|
}
|
|
34
|
-
if (key === "location"
|
|
35
|
-
value = replaceUrls(value);
|
|
58
|
+
if (key === "location") {
|
|
59
|
+
value = serverContext.replaceUrls(value);
|
|
36
60
|
}
|
|
37
61
|
res.headers.set(key, value);
|
|
38
62
|
});
|
|
@@ -46,22 +70,25 @@ export async function proxyWpAdmin(event, serverContext) {
|
|
|
46
70
|
// Replace URLs pointing to the origin server from the response itself
|
|
47
71
|
// This is only done for text-based content types, like application/json, text/plain, text/html etc
|
|
48
72
|
if (contentType?.match(/(application|text)\//)) {
|
|
49
|
-
|
|
50
|
-
body = replaceUrls((await response.text()) ?? "");
|
|
51
|
-
}
|
|
73
|
+
body = serverContext.replaceUrls((await response.text()) ?? "", reqUrl.origin);
|
|
52
74
|
// If the content type is text/html, inject the Vite assets into the response — assuming the placeholder comments are found
|
|
53
75
|
if (contentType.startsWith("text/html")) {
|
|
54
|
-
const clientManifest = getManifest("admin");
|
|
76
|
+
const clientManifest = serverContext.runtime.getManifest("admin");
|
|
55
77
|
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
const getViteHeader = () => assets.map((asset) => renderAsset(asset)).join("\n");
|
|
79
|
+
const getViteFooter = () => renderAsset({
|
|
58
80
|
tag: "script",
|
|
59
81
|
attrs: {
|
|
60
82
|
type: "module",
|
|
61
83
|
src: clientManifest.inputs[clientManifest.handler].output.path,
|
|
62
84
|
},
|
|
63
85
|
children: "",
|
|
64
|
-
})
|
|
86
|
+
});
|
|
87
|
+
const encodeForJSON = (str) => JSON.stringify(str).slice(1, -1).replaceAll("/", "\\/");
|
|
88
|
+
body = body.replaceAll("<!---VITE_HEADER--->", getViteHeader());
|
|
89
|
+
body = body.replaceAll("<!---VITE_FOOTER--->", getViteFooter());
|
|
90
|
+
body = body.replaceAll("<script id='vite-iframe-header'><\\/script>", encodeForJSON(getViteHeader()));
|
|
91
|
+
body = body.replaceAll("<script id='vite-iframe-footer'><\\/script>", encodeForJSON(getViteFooter()));
|
|
65
92
|
}
|
|
66
93
|
}
|
|
67
94
|
else {
|
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { RouteDataWithTrackers } from "../lib/routing/types.js";
|
|
2
|
+
type SSRArgs = {
|
|
3
|
+
pathname: string;
|
|
4
|
+
initialData: RouteDataWithTrackers;
|
|
5
|
+
};
|
|
6
|
+
export declare function getSsrStream(args: SSRArgs): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
7
|
+
type RenderArgs = {
|
|
8
|
+
pathname: string;
|
|
9
|
+
statusCode?: number;
|
|
10
|
+
newOrigin?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function renderPage(args: RenderArgs): Promise<Response>;
|
|
13
|
+
type RenderErrorPageArgs = {
|
|
14
|
+
pathname: string;
|
|
15
|
+
code: number;
|
|
16
|
+
title: string;
|
|
17
|
+
newOrigin?: string;
|
|
18
|
+
realError?: Error;
|
|
19
|
+
};
|
|
20
|
+
export declare function renderErrorPage(args: RenderErrorPageArgs): Promise<Response>;
|
|
21
|
+
type Asset = {
|
|
22
|
+
tag: string;
|
|
23
|
+
attrs: Record<string, string | boolean>;
|
|
24
|
+
children?: string;
|
|
25
|
+
};
|
|
26
|
+
export declare function renderAsset({ tag, attrs, children }: Asset): string;
|
|
27
|
+
export {};
|
|
@@ -1,22 +1,202 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getManifest } from "vinxi/manifest";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { renderToPipeableStream, renderToString } from "react-dom/server";
|
|
3
|
+
import { Writable } from "stream";
|
|
4
|
+
import { MetaTags } from "../entry/MetaTags.js";
|
|
6
5
|
import { SSRRoot } from "../entry/ssr-root.js";
|
|
7
6
|
import { RouteLoader } from "../lib/routing/loader.js";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
7
|
+
import { AssetCaptureContext } from "../utils/asset-capture.js";
|
|
8
|
+
import { ServerContext } from "./server-context.js";
|
|
9
|
+
import { Suspense } from "react";
|
|
10
|
+
export async function getSsrStream(args) {
|
|
11
|
+
const clientManifest = ServerContext.main.runtime.getManifest("client");
|
|
12
|
+
const preloadAssets = new Set([clientManifest.handler]);
|
|
13
|
+
const includedAssets = new Set();
|
|
14
|
+
const jsx = (_jsx(Suspense, { children: _jsx(AssetCaptureContext.Provider, { value: preloadAssets, children: _jsx(SSRRoot, { metaTags: args.initialData?.meta?.head || [], pathname: args.pathname, initialData: args.initialData, loader: new RouteLoader() }) }) }));
|
|
15
|
+
const stream = await new Promise(async (resolve, reject) => {
|
|
16
|
+
// console.log("Rendering to pipable")
|
|
13
17
|
const stream = renderToPipeableStream(jsx, {
|
|
18
|
+
identifierPrefix: "ed",
|
|
14
19
|
onShellReady() {
|
|
20
|
+
// console.log("Shell ready")
|
|
15
21
|
resolve(stream);
|
|
16
22
|
},
|
|
23
|
+
onShellError(err) {
|
|
24
|
+
console.log("onShellError", err);
|
|
25
|
+
reject(err);
|
|
26
|
+
},
|
|
27
|
+
onError(err, errInfo) {
|
|
28
|
+
console.log("Error occurred after shell ready", err, errInfo);
|
|
29
|
+
console.error(err);
|
|
30
|
+
},
|
|
17
31
|
bootstrapModules: [clientManifest.inputs[clientManifest.handler].output.path],
|
|
18
|
-
bootstrapScriptContent:
|
|
32
|
+
bootstrapScriptContent: `\nwindow.manifest = ${JSON.stringify(await clientManifest.json())};\nwindow._PAGE_DATA = ${JSON.stringify({
|
|
33
|
+
...args.initialData,
|
|
34
|
+
trackers: undefined,
|
|
35
|
+
})};\n`,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
const [initial, middle, end] = renderToString(_jsxs("html", { lang: "en", children: [_jsxs("head", { children: ["%%$%%", _jsx(MetaTags, { tags: args.initialData.meta?.head ?? [] }), "%%trackers_head%%"] }), _jsxs("body", { children: ["%%trackers_body%%", _jsx("div", { id: "root", children: "%%$%%" }), "%%trackers_footer%%"] })] }))
|
|
39
|
+
.replace(/%%trackers_(head|body|footer)%%/g, (_, name) => {
|
|
40
|
+
return args.initialData.trackers?.[name] || "";
|
|
41
|
+
})
|
|
42
|
+
.split("%%$%%");
|
|
43
|
+
return new ReadableStream({
|
|
44
|
+
async start(controller) {
|
|
45
|
+
controller.enqueue(new TextEncoder().encode(initial));
|
|
46
|
+
const inner = await new Promise((resolve, reject) => {
|
|
47
|
+
let buffer = [];
|
|
48
|
+
const writableStream = new Writable({
|
|
49
|
+
emitClose: true,
|
|
50
|
+
write(chunk, encoding, callback) {
|
|
51
|
+
buffer.push(chunk);
|
|
52
|
+
// controller.enqueue(chunk)
|
|
53
|
+
callback();
|
|
54
|
+
},
|
|
55
|
+
final(callback) {
|
|
56
|
+
resolve(buffer);
|
|
57
|
+
// controller.close()
|
|
58
|
+
callback();
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
stream.pipe(writableStream);
|
|
62
|
+
});
|
|
63
|
+
for (const input of preloadAssets) {
|
|
64
|
+
const assets = await clientManifest.inputs[input].assets();
|
|
65
|
+
// controller.enqueue(new TextEncoder().encode(`\n<!-- for ${input} -->`))
|
|
66
|
+
for (const _asset of assets) {
|
|
67
|
+
const asset = _asset;
|
|
68
|
+
// Ensure that each asset is only included once
|
|
69
|
+
const key = asset?.attrs?.key;
|
|
70
|
+
if (!key) {
|
|
71
|
+
throw new Error("Asset must have a key: " + JSON.stringify(asset));
|
|
72
|
+
}
|
|
73
|
+
if (includedAssets.has(key))
|
|
74
|
+
continue;
|
|
75
|
+
includedAssets.add(key);
|
|
76
|
+
// Render the asset
|
|
77
|
+
try {
|
|
78
|
+
const tag = renderAsset(asset);
|
|
79
|
+
controller.enqueue(new TextEncoder().encode(tag + "\n"));
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
controller.enqueue(new TextEncoder().encode(`\n<!-- ${JSON.stringify(err)} -->\n`));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// console.log("ASSETS", await clientManifest)
|
|
87
|
+
controller.enqueue(new TextEncoder().encode(middle));
|
|
88
|
+
for (const chunk of inner) {
|
|
89
|
+
controller.enqueue(chunk);
|
|
90
|
+
}
|
|
91
|
+
controller.enqueue(new TextEncoder().encode(end));
|
|
92
|
+
// console.log("Assets", dynamicAssets)
|
|
93
|
+
controller.close();
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
export async function renderPage(args) {
|
|
98
|
+
const serverContext = ServerContext.main;
|
|
99
|
+
let headers = new Headers();
|
|
100
|
+
let responseInit = {
|
|
101
|
+
headers,
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
const [{ appData, trackers }, response] = await Promise.all([
|
|
105
|
+
serverContext.fetchAppData(),
|
|
106
|
+
serverContext.fetchRouteData({
|
|
107
|
+
pathname: args.pathname,
|
|
108
|
+
newOrigin: args.newOrigin,
|
|
109
|
+
}),
|
|
110
|
+
]);
|
|
111
|
+
let data;
|
|
112
|
+
try {
|
|
113
|
+
data = await response.json();
|
|
114
|
+
data.appData = appData;
|
|
115
|
+
data.trackers = trackers;
|
|
116
|
+
responseInit.status = response.status;
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
console.error(err);
|
|
120
|
+
return renderErrorPage({
|
|
121
|
+
pathname: args.pathname,
|
|
122
|
+
code: 500,
|
|
123
|
+
newOrigin: args.newOrigin,
|
|
124
|
+
realError: err,
|
|
125
|
+
title: "Internal Server Error",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (data.redirect) {
|
|
129
|
+
return new Response(null, {
|
|
130
|
+
status: data.status || 302,
|
|
131
|
+
headers: {
|
|
132
|
+
Location: data.redirect,
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
headers.set("Content-Type", "text/html; charset=utf-8");
|
|
137
|
+
const stream = await getSsrStream({
|
|
138
|
+
...args,
|
|
139
|
+
initialData: data,
|
|
140
|
+
});
|
|
141
|
+
return new Response(stream, responseInit);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
console.error(err);
|
|
145
|
+
if (args.statusCode !== 500) {
|
|
146
|
+
return renderErrorPage({
|
|
147
|
+
pathname: args.pathname,
|
|
148
|
+
code: 500,
|
|
149
|
+
newOrigin: args.newOrigin,
|
|
150
|
+
realError: err,
|
|
151
|
+
title: "Internal Server Error",
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return new Response('<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"' +
|
|
155
|
+
String(err) +
|
|
156
|
+
'"</p></body></html>', {
|
|
157
|
+
status: 500,
|
|
158
|
+
statusText: "Internal Server Error",
|
|
159
|
+
headers: {
|
|
160
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
161
|
+
},
|
|
19
162
|
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export async function renderErrorPage(args) {
|
|
166
|
+
return renderPage({
|
|
167
|
+
pathname: "/_error",
|
|
168
|
+
statusCode: args.code,
|
|
169
|
+
newOrigin: args.newOrigin,
|
|
20
170
|
});
|
|
21
|
-
|
|
171
|
+
}
|
|
172
|
+
export function renderAsset({ tag, attrs, children }) {
|
|
173
|
+
const formatAttributes = (attributes) => {
|
|
174
|
+
return Object.entries(attributes)
|
|
175
|
+
.map(([attr, value]) => {
|
|
176
|
+
if (value === true) {
|
|
177
|
+
return attr;
|
|
178
|
+
}
|
|
179
|
+
else if (value !== false && value != null) {
|
|
180
|
+
return `${attr}="${String(value).replace(/"/g, """)}"`;
|
|
181
|
+
}
|
|
182
|
+
return "";
|
|
183
|
+
})
|
|
184
|
+
.filter(Boolean)
|
|
185
|
+
.join(" ");
|
|
186
|
+
};
|
|
187
|
+
switch (tag) {
|
|
188
|
+
case "script":
|
|
189
|
+
if (attrs.src) {
|
|
190
|
+
return `<script ${formatAttributes(attrs)}></script>`;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
return `<script ${formatAttributes(attrs)}>${children ?? ""}</script>`;
|
|
194
|
+
}
|
|
195
|
+
case "link":
|
|
196
|
+
return `<link ${formatAttributes(attrs)} />`;
|
|
197
|
+
case "style":
|
|
198
|
+
return `<style ${formatAttributes(attrs)}>${children ?? ""}</style>`;
|
|
199
|
+
default:
|
|
200
|
+
return "";
|
|
201
|
+
}
|
|
22
202
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { AnyProcedure } from "@trpc/server";
|
|
2
|
+
import { FetchCreateContextFnOptions } from "@trpc/server/adapters/fetch";
|
|
3
|
+
export declare const rpcApi: {
|
|
4
|
+
_config: import("@trpc/server/unstable-core-do-not-import").RootConfig<{
|
|
5
|
+
ctx: RPCContext;
|
|
6
|
+
meta: object;
|
|
7
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
8
|
+
transformer: true;
|
|
9
|
+
}>;
|
|
10
|
+
procedure: import("@trpc/server/unstable-core-do-not-import").ProcedureBuilder<RPCContext, object, object, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, false>;
|
|
11
|
+
middleware: <$ContextOverrides>(fn: import("@trpc/server/unstable-core-do-not-import").MiddlewareFunction<RPCContext, object, object, $ContextOverrides, unknown>) => import("@trpc/server/unstable-core-do-not-import").MiddlewareBuilder<RPCContext, object, $ContextOverrides, unknown>;
|
|
12
|
+
router: {
|
|
13
|
+
<TInput extends import("@trpc/server").RouterRecord>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
|
|
14
|
+
ctx: RPCContext;
|
|
15
|
+
meta: object;
|
|
16
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
17
|
+
transformer: true;
|
|
18
|
+
}, TInput>;
|
|
19
|
+
<TInput extends import("@trpc/server/unstable-core-do-not-import").CreateRouterOptions>(input: TInput): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
|
|
20
|
+
ctx: RPCContext;
|
|
21
|
+
meta: object;
|
|
22
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
23
|
+
transformer: true;
|
|
24
|
+
}, import("@trpc/server/unstable-core-do-not-import").DecorateCreateRouterOptions<TInput>>;
|
|
25
|
+
};
|
|
26
|
+
mergeRouters: typeof import("@trpc/server/unstable-core-do-not-import").mergeRouters;
|
|
27
|
+
createCallerFactory: <TRecord extends import("@trpc/server").RouterRecord>(router: Pick<import("@trpc/server/unstable-core-do-not-import").Router<{
|
|
28
|
+
ctx: RPCContext;
|
|
29
|
+
meta: object;
|
|
30
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
31
|
+
transformer: true;
|
|
32
|
+
}, TRecord>, "_def">) => import("@trpc/server/unstable-core-do-not-import").RouterCaller<{
|
|
33
|
+
ctx: RPCContext;
|
|
34
|
+
meta: object;
|
|
35
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
36
|
+
transformer: true;
|
|
37
|
+
}, TRecord>;
|
|
38
|
+
};
|
|
39
|
+
type RouterSchema = Record<string, Record<string, AnyProcedure> | AnyProcedure>;
|
|
40
|
+
export declare const rpc: {
|
|
41
|
+
middleware: <$ContextOverrides>(fn: import("@trpc/server/unstable-core-do-not-import").MiddlewareFunction<RPCContext, object, object, $ContextOverrides, unknown>) => import("@trpc/server/unstable-core-do-not-import").MiddlewareBuilder<RPCContext, object, $ContextOverrides, unknown>;
|
|
42
|
+
procedure: import("@trpc/server/unstable-core-do-not-import").ProcedureBuilder<RPCContext, object, object, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, typeof import("@trpc/server/unstable-core-do-not-import").unsetMarker, false>;
|
|
43
|
+
router<T extends RouterSchema>(routes: T): T;
|
|
44
|
+
};
|
|
45
|
+
export declare function defineServerContext<T>(func: (opts: FetchCreateContextFnOptions) => T): (opts: FetchCreateContextFnOptions) => T;
|
|
46
|
+
export declare function instantiateRouter<T extends RouterSchema>(routes: T): import("@trpc/server/unstable-core-do-not-import").BuiltRouter<{
|
|
47
|
+
ctx: RPCContext;
|
|
48
|
+
meta: object;
|
|
49
|
+
errorShape: import("@trpc/server/unstable-core-do-not-import").DefaultErrorShape;
|
|
50
|
+
transformer: true;
|
|
51
|
+
}, T>;
|
|
52
|
+
export type InferRPCServerContext<TFunc extends null | ((opts: FetchCreateContextFnOptions) => any)> = {
|
|
53
|
+
req: Request;
|
|
54
|
+
resHeaders: Headers;
|
|
55
|
+
} & (TFunc extends (opts: FetchCreateContextFnOptions) => infer T ? T : {});
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { initTRPC } from "@trpc/server";
|
|
2
|
+
import superjson from "superjson";
|
|
3
|
+
export const rpcApi = initTRPC.context().create({
|
|
4
|
+
transformer: superjson,
|
|
5
|
+
});
|
|
6
|
+
export const rpc = {
|
|
7
|
+
middleware: rpcApi.middleware,
|
|
8
|
+
procedure: rpcApi.procedure,
|
|
9
|
+
router(routes) {
|
|
10
|
+
return routes;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
export function defineServerContext(func) {
|
|
14
|
+
return func;
|
|
15
|
+
}
|
|
16
|
+
export function instantiateRouter(routes) {
|
|
17
|
+
return rpcApi.router(routes);
|
|
18
|
+
}
|
|
@@ -1,25 +1,49 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Manifest } from "vinxi/dist/types/types/manifest";
|
|
2
2
|
import { RequestHeaders } from "vinxi/http";
|
|
3
|
+
import type { EDConfig } from "../../node/project/config.js";
|
|
4
|
+
import { TrackerTags } from "../lib/routing/types.js";
|
|
5
|
+
import { UrlReplacerConf } from "./utils/replace-host.js";
|
|
6
|
+
import { QueryMonitor } from "../utils/query-monitor.js";
|
|
3
7
|
export type ServerContextArgs = {
|
|
4
8
|
dev: boolean;
|
|
5
9
|
origin: string;
|
|
6
10
|
replaceUrls?: UrlReplacerConf;
|
|
11
|
+
rpcBases?: string[];
|
|
12
|
+
config: EDConfig;
|
|
13
|
+
};
|
|
14
|
+
export type ServerContextRuntime = {
|
|
15
|
+
getManifest: (name: string) => Manifest;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Data returned from WordPress origin /_appdata route
|
|
19
|
+
*/
|
|
20
|
+
type ServerAppData = {
|
|
21
|
+
appData: any;
|
|
22
|
+
trackers: TrackerTags;
|
|
7
23
|
};
|
|
8
24
|
export declare class ServerContext {
|
|
9
25
|
dev: boolean;
|
|
10
26
|
origin: string;
|
|
11
|
-
|
|
27
|
+
_urlReplacer?: (text: string, origin?: string) => string;
|
|
28
|
+
rpcBases: string[];
|
|
29
|
+
config: EDConfig;
|
|
30
|
+
static main: ServerContext;
|
|
12
31
|
constructor(conf: ServerContextArgs);
|
|
32
|
+
replaceUrls(text: string, origin?: string): string;
|
|
33
|
+
get runtime(): ServerContextRuntime;
|
|
34
|
+
static setRuntime(rt: ServerContextRuntime): void;
|
|
13
35
|
getOriginUrl(url: string): string;
|
|
14
36
|
fetchOrigin(url: string, opts?: RequestInit & {
|
|
15
37
|
replaceUrls?: boolean;
|
|
38
|
+
newOrigin?: string;
|
|
16
39
|
}): Promise<Response>;
|
|
40
|
+
debugLogQueryMonitor(kind: "props" | "mutation" | "query" | "app", uri: string, monitor: QueryMonitor.Entry[]): void;
|
|
17
41
|
fetchRouteData(req: {
|
|
18
42
|
pathname: string;
|
|
19
|
-
query?: Record<string, any>;
|
|
20
43
|
headers?: RequestHeaders;
|
|
21
|
-
|
|
44
|
+
newOrigin?: string;
|
|
22
45
|
}): Promise<Response>;
|
|
46
|
+
fetchAppData(): Promise<ServerAppData>;
|
|
23
47
|
extractRequestHeaders(req?: RequestHeaders): Partial<Record<import("vinxi/http").HTTPHeaderName, string | undefined>>;
|
|
24
48
|
fetchNamedQuery(req: {
|
|
25
49
|
name: string;
|
|
@@ -31,4 +55,20 @@ export declare class ServerContext {
|
|
|
31
55
|
body: object;
|
|
32
56
|
headers: RequestHeaders;
|
|
33
57
|
}): Promise<Response>;
|
|
58
|
+
get allowedCorsOrigins(): string[];
|
|
59
|
+
getCorsOrigin(originHeader: string): string | undefined;
|
|
60
|
+
getCorsHeaders(origin: string): {
|
|
61
|
+
"Access-Control-Allow-Methods"?: undefined;
|
|
62
|
+
"Access-Control-Allow-Origin"?: undefined;
|
|
63
|
+
"Access-Control-Allow-Credentials"?: undefined;
|
|
64
|
+
"Access-Control-Allow-Headers"?: undefined;
|
|
65
|
+
"Access-Control-Expose-Headers"?: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
"Access-Control-Allow-Methods": string;
|
|
68
|
+
"Access-Control-Allow-Origin": string;
|
|
69
|
+
"Access-Control-Allow-Credentials": string;
|
|
70
|
+
"Access-Control-Allow-Headers": string;
|
|
71
|
+
"Access-Control-Expose-Headers": string;
|
|
72
|
+
};
|
|
34
73
|
}
|
|
74
|
+
export {};
|