eddev 2.0.0-beta.69 → 2.0.0-beta.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/entry/boot-admin.js +0 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +1 -1
- package/dist/app/lib/routing/components/Link.js +2 -2
- package/dist/app/lib/routing/loader.js +14 -9
- package/dist/app/lib/routing/utils.js +2 -1
- package/dist/app/server/proxy-wp-admin.js +15 -1
- package/dist/app/server/render-ssr-page.d.ts +7 -0
- package/dist/app/server/render-ssr-page.js +45 -0
- package/dist/app/server/server-context.js +21 -6
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/vinxi-app.js +12 -6
- package/dist/node/project/config.d.ts +5 -0
- package/dist/node/project/config.js +5 -2
- package/package.json +1 -1
|
@@ -214,7 +214,7 @@ export function BrowserRouter(props) {
|
|
|
214
214
|
hash: link.hash,
|
|
215
215
|
search: "",
|
|
216
216
|
query: link.query,
|
|
217
|
-
pathname: link.pathname,
|
|
217
|
+
pathname: data.canonical ?? link.pathname,
|
|
218
218
|
view: data.view,
|
|
219
219
|
props: data.viewData?.data ?? {},
|
|
220
220
|
component: lazyComponent,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useMemo } from "react";
|
|
3
|
-
import { parseURL, resolveURL, withoutTrailingSlash } from "ufo";
|
|
3
|
+
import { parseURL, resolveURL, withoutTrailingSlash, withTrailingSlash } from "ufo";
|
|
4
4
|
import { useIsSSR } from "../hooks/useIsSSR.js";
|
|
5
5
|
import { useRouter } from "../hooks/useRouter.js";
|
|
6
6
|
import { isSameOrigin } from "../utils.js";
|
|
@@ -17,7 +17,7 @@ export const Link = forwardRef(({ preferBack, ...props }, ref) => {
|
|
|
17
17
|
else {
|
|
18
18
|
const router = useRouter();
|
|
19
19
|
const state = useLinkState(props.href ?? "");
|
|
20
|
-
return (_jsx(Comp, { ref: ref, "data-active": state.active ?? undefined, "data-child-active": state.childActive ?? undefined, "data-pending": state.pending ?? undefined, ...props, href: props.href ?? undefined, onMouseEnter: (e) => {
|
|
20
|
+
return (_jsx(Comp, { ref: ref, "data-active": state.active ?? undefined, "data-child-active": state.childActive ?? undefined, "data-pending": state.pending ?? undefined, ...props, href: withTrailingSlash(props.href ?? undefined), onMouseEnter: (e) => {
|
|
21
21
|
if (props.onMouseEnter) {
|
|
22
22
|
props.onMouseEnter(e);
|
|
23
23
|
}
|
|
@@ -56,6 +56,7 @@ export class RouteLoader {
|
|
|
56
56
|
return this.entries.has(cacheKey);
|
|
57
57
|
}
|
|
58
58
|
async loadRouteData(pathname, withAppData = false) {
|
|
59
|
+
pathname = withTrailingSlash(pathname);
|
|
59
60
|
const cacheKey = this.getKey(pathname);
|
|
60
61
|
// Cached value?
|
|
61
62
|
if (this.entries.has(cacheKey))
|
|
@@ -65,9 +66,12 @@ export class RouteLoader {
|
|
|
65
66
|
serverless: env.serverless,
|
|
66
67
|
debug: env.dev,
|
|
67
68
|
});
|
|
68
|
-
const promise = this.fetchImpl(requestUrl
|
|
69
|
-
.then((response) =>
|
|
70
|
-
.
|
|
69
|
+
const promise = this.fetchImpl(requestUrl)
|
|
70
|
+
.then(async (response) => {
|
|
71
|
+
if (response.redirected) {
|
|
72
|
+
return { redirect: response.url };
|
|
73
|
+
}
|
|
74
|
+
let text = await response.text();
|
|
71
75
|
if (this.processProps) {
|
|
72
76
|
text = this.processProps(text);
|
|
73
77
|
}
|
|
@@ -78,14 +82,15 @@ export class RouteLoader {
|
|
|
78
82
|
throw new RouteError(`JSON parse error for route '${pathname}':\n${err?.message}`, 500);
|
|
79
83
|
}
|
|
80
84
|
})
|
|
81
|
-
.then((data) => {
|
|
85
|
+
.then(async (data) => {
|
|
82
86
|
if (data.redirect) {
|
|
83
|
-
const redirect = data.redirect;
|
|
84
|
-
data = this.loadRouteData(redirect)
|
|
85
|
-
|
|
86
|
-
return data;
|
|
87
|
-
});
|
|
87
|
+
const redirect = parseURL(data.redirect).pathname;
|
|
88
|
+
data = await this.loadRouteData(redirect);
|
|
89
|
+
data.canonical = redirect;
|
|
88
90
|
}
|
|
91
|
+
return data;
|
|
92
|
+
})
|
|
93
|
+
.then((data) => {
|
|
89
94
|
this.entries.set(cacheKey, new Promise((resolve) => resolve(data)));
|
|
90
95
|
return data;
|
|
91
96
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parse as qsParse, stringify as qsStringify } from "qs";
|
|
2
|
-
import { parseURL, resolveURL, stringifyParsedURL, withoutTrailingSlash } from "ufo";
|
|
2
|
+
import { parseURL, resolveURL, stringifyParsedURL, withoutTrailingSlash, withTrailingSlash } from "ufo";
|
|
3
3
|
export function isSameOrigin(url) {
|
|
4
4
|
if (typeof document === "undefined") {
|
|
5
5
|
return url.startsWith("/");
|
|
@@ -81,6 +81,7 @@ export function normalizeRoute(route) {
|
|
|
81
81
|
export function stringifyRouteLink(route) {
|
|
82
82
|
return stringifyParsedURL({
|
|
83
83
|
...route,
|
|
84
|
+
pathname: withTrailingSlash(route.pathname),
|
|
84
85
|
search: stringifyQuery(route.query),
|
|
85
86
|
});
|
|
86
87
|
}
|
|
@@ -2,11 +2,25 @@
|
|
|
2
2
|
import { splitSetCookieString } from "cookie-es";
|
|
3
3
|
import { getProxyRequestHeaders, getRequestURL, getWebRequest } from "vinxi/http";
|
|
4
4
|
import { ServerContext } from "./server-context.js";
|
|
5
|
+
import { renderErrorPage } from "./render-ssr-page.js";
|
|
5
6
|
export async function proxyWpAdmin(event) {
|
|
6
7
|
const serverContext = ServerContext.main;
|
|
7
8
|
const replaceUrls = serverContext.replaceUrls;
|
|
8
9
|
const req = getWebRequest(event);
|
|
9
|
-
const
|
|
10
|
+
const reqUrl = getRequestURL(event);
|
|
11
|
+
const serverlessConfig = serverContext.config.serverless;
|
|
12
|
+
if (!serverContext.dev) {
|
|
13
|
+
if (reqUrl.pathname.toLowerCase().match(/\/+(graphql|wp\-(admin|login|json))/)) {
|
|
14
|
+
if (serverlessConfig.admin === "hide") {
|
|
15
|
+
return renderErrorPage({
|
|
16
|
+
code: 404,
|
|
17
|
+
pathname: reqUrl.pathname,
|
|
18
|
+
title: "Not Found",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const proxyUrl = serverContext.getOriginUrl(reqUrl.href);
|
|
10
24
|
// Prepare request headers to be sent to the origin server
|
|
11
25
|
const proxyHeaders = getProxyRequestHeaders(event);
|
|
12
26
|
proxyHeaders["X-ED-Dev-Proxy"] = "true";
|
|
@@ -6,6 +6,13 @@ type SSRArgs = {
|
|
|
6
6
|
export declare function getSsrStream(args: SSRArgs): Promise<ReadableStream<Uint8Array>>;
|
|
7
7
|
type RenderArgs = {
|
|
8
8
|
pathname: string;
|
|
9
|
+
statusCode?: number;
|
|
9
10
|
};
|
|
10
11
|
export declare function renderPage(args: RenderArgs): Promise<Response>;
|
|
12
|
+
type RenderErrorPageArgs = {
|
|
13
|
+
pathname: string;
|
|
14
|
+
code: number;
|
|
15
|
+
title: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function renderErrorPage(args: RenderErrorPageArgs): Promise<Response>;
|
|
11
18
|
export {};
|
|
@@ -67,6 +67,7 @@ export async function renderPage(args) {
|
|
|
67
67
|
data = await response.json();
|
|
68
68
|
data.appData = appData;
|
|
69
69
|
data.trackers = trackers;
|
|
70
|
+
responseInit.status = response.status;
|
|
70
71
|
}
|
|
71
72
|
catch (err) {
|
|
72
73
|
data = {
|
|
@@ -74,6 +75,7 @@ export async function renderPage(args) {
|
|
|
74
75
|
viewType: "react",
|
|
75
76
|
viewData: {},
|
|
76
77
|
appData: appData,
|
|
78
|
+
trackers: trackers,
|
|
77
79
|
};
|
|
78
80
|
console.error(err);
|
|
79
81
|
responseInit.status = 500;
|
|
@@ -98,3 +100,46 @@ export async function renderPage(args) {
|
|
|
98
100
|
});
|
|
99
101
|
}
|
|
100
102
|
}
|
|
103
|
+
export async function renderErrorPage(args) {
|
|
104
|
+
return renderPage({
|
|
105
|
+
pathname: "/_error",
|
|
106
|
+
statusCode: args.code,
|
|
107
|
+
});
|
|
108
|
+
// const serverContext = ServerContext.main
|
|
109
|
+
// let headers = new Headers()
|
|
110
|
+
// let responseInit: ResponseInit = {
|
|
111
|
+
// headers,
|
|
112
|
+
// }
|
|
113
|
+
// try {
|
|
114
|
+
// const { appData, trackers } = await serverContext.fetchAppData()
|
|
115
|
+
// let data: RouteDataWithTrackers
|
|
116
|
+
// data = {
|
|
117
|
+
// view: "_error",
|
|
118
|
+
// viewType: "react",
|
|
119
|
+
// viewData: {},
|
|
120
|
+
// appData,
|
|
121
|
+
// trackers,
|
|
122
|
+
// }
|
|
123
|
+
// responseInit.status = 500
|
|
124
|
+
// headers.set("Content-Type", "text/html; charset=utf-8")
|
|
125
|
+
// const stream = await getSsrStream({
|
|
126
|
+
// ...args,
|
|
127
|
+
// initialData: data,
|
|
128
|
+
// })
|
|
129
|
+
// return new Response(stream, responseInit)
|
|
130
|
+
// } catch (err) {
|
|
131
|
+
// console.error(err)
|
|
132
|
+
// return new Response(
|
|
133
|
+
// '<!DOCTYPE html><html><head><title>500 Internal Server Error</title></head><body><h1>500 Internal Server Error</h1><p>"' +
|
|
134
|
+
// String(err) +
|
|
135
|
+
// '"</p></body></html>',
|
|
136
|
+
// {
|
|
137
|
+
// status: 500,
|
|
138
|
+
// statusText: "Internal Server Error",
|
|
139
|
+
// headers: {
|
|
140
|
+
// "Content-Type": "text/html; charset=utf-8",
|
|
141
|
+
// },
|
|
142
|
+
// },
|
|
143
|
+
// )
|
|
144
|
+
// }
|
|
145
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseURL, stringifyParsedURL, withQuery } from "ufo";
|
|
1
|
+
import { parseURL, stringifyParsedURL, withQuery, withTrailingSlash } from "ufo";
|
|
2
2
|
import { filterHeader } from "./utils/headers.js";
|
|
3
3
|
import { createUrlReplacer } from "./utils/replace-host.js";
|
|
4
4
|
const PROXY_RESPONSE_HEADERS = ["content-type", "set-cookie", /^x-/, "cache-control", /woocommerce/];
|
|
@@ -76,22 +76,39 @@ export class ServerContext {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
async fetchRouteData(req) {
|
|
79
|
-
const fetchUrl = withQuery(req.pathname, {
|
|
79
|
+
const fetchUrl = withQuery(withTrailingSlash(req.pathname), {
|
|
80
80
|
...req.query,
|
|
81
81
|
_props: "1",
|
|
82
82
|
_ssr: "1",
|
|
83
83
|
_debug: this.dev ? "1" : undefined,
|
|
84
84
|
});
|
|
85
85
|
// console.log("Fetching route data", req.pathname)
|
|
86
|
-
const result = this.fetchOrigin(fetchUrl, {
|
|
86
|
+
const result = await this.fetchOrigin(fetchUrl, {
|
|
87
87
|
cache: "no-cache",
|
|
88
88
|
replaceUrls: true,
|
|
89
89
|
headers: {
|
|
90
90
|
"Content-Type": "application/json",
|
|
91
91
|
Accept: "application/json",
|
|
92
92
|
},
|
|
93
|
+
redirect: "manual",
|
|
93
94
|
});
|
|
94
|
-
|
|
95
|
+
if (result.headers.get("content-type") && result.headers.get("location")) {
|
|
96
|
+
let location = result.headers.get("location");
|
|
97
|
+
let status = result.status;
|
|
98
|
+
if (this.replaceUrls) {
|
|
99
|
+
location = this.replaceUrls(location);
|
|
100
|
+
}
|
|
101
|
+
const headers = new Headers({
|
|
102
|
+
...result.headers,
|
|
103
|
+
});
|
|
104
|
+
headers.delete("location");
|
|
105
|
+
return new Response(JSON.stringify({
|
|
106
|
+
redirect: location,
|
|
107
|
+
status: status,
|
|
108
|
+
}), {
|
|
109
|
+
headers: headers,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
95
112
|
return result;
|
|
96
113
|
}
|
|
97
114
|
async fetchAppData() {
|
|
@@ -130,7 +147,6 @@ export class ServerContext {
|
|
|
130
147
|
"Content-Type": "application/json",
|
|
131
148
|
Accept: "application/json",
|
|
132
149
|
},
|
|
133
|
-
redirect: "manual",
|
|
134
150
|
});
|
|
135
151
|
}
|
|
136
152
|
async fetchMutation(req) {
|
|
@@ -145,7 +161,6 @@ export class ServerContext {
|
|
|
145
161
|
Accept: "application/json",
|
|
146
162
|
},
|
|
147
163
|
body: JSON.stringify(req.body),
|
|
148
|
-
redirect: "manual",
|
|
149
164
|
});
|
|
150
165
|
}
|
|
151
166
|
get allowedCorsOrigins() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.70";
|
package/dist/node/cli/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.70";
|
|
@@ -79,12 +79,18 @@ export function createVinxiApp(args) {
|
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
81
|
routers: [
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
...args.config.serverless.themeAssets.map((folder) => {
|
|
83
|
+
const folderName = folder
|
|
84
|
+
.split("/")
|
|
85
|
+
.filter((p) => !p.includes("*") && p !== ".")
|
|
86
|
+
.join("/");
|
|
87
|
+
return {
|
|
88
|
+
name: "public_" + folderName,
|
|
89
|
+
type: "static",
|
|
90
|
+
dir: "./" + folderName,
|
|
91
|
+
base: joinURL(args.publicUrl, folderName),
|
|
92
|
+
};
|
|
93
|
+
}),
|
|
88
94
|
{
|
|
89
95
|
name: "data-api",
|
|
90
96
|
type: "http",
|
|
@@ -28,6 +28,7 @@ export declare const EDConfigSchema: z.ZodObject<{
|
|
|
28
28
|
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
29
29
|
uploads: z.ZodEnum<["proxy", "remote"]>;
|
|
30
30
|
plugins: z.ZodDefault<z.ZodEnum<["proxy", "remote"]>>;
|
|
31
|
+
admin: z.ZodDefault<z.ZodEnum<["proxy", "hide"]>>;
|
|
31
32
|
themeAssets: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
32
33
|
apiOnly: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
33
34
|
endpoints: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
@@ -44,6 +45,7 @@ export declare const EDConfigSchema: z.ZodObject<{
|
|
|
44
45
|
plugins: "proxy" | "remote";
|
|
45
46
|
enabled: boolean;
|
|
46
47
|
uploads: "proxy" | "remote";
|
|
48
|
+
admin: "hide" | "proxy";
|
|
47
49
|
themeAssets: string[];
|
|
48
50
|
apiOnly: boolean;
|
|
49
51
|
endpoints: Record<string, string>;
|
|
@@ -57,6 +59,7 @@ export declare const EDConfigSchema: z.ZodObject<{
|
|
|
57
59
|
endpoints: Record<string, string>;
|
|
58
60
|
plugins?: "proxy" | "remote" | undefined;
|
|
59
61
|
enabled?: boolean | undefined;
|
|
62
|
+
admin?: "hide" | "proxy" | undefined;
|
|
60
63
|
themeAssets?: string[] | undefined;
|
|
61
64
|
apiOnly?: boolean | undefined;
|
|
62
65
|
defaultRevalidate?: number | undefined;
|
|
@@ -84,6 +87,7 @@ export declare const EDConfigSchema: z.ZodObject<{
|
|
|
84
87
|
plugins: "proxy" | "remote";
|
|
85
88
|
enabled: boolean;
|
|
86
89
|
uploads: "proxy" | "remote";
|
|
90
|
+
admin: "hide" | "proxy";
|
|
87
91
|
themeAssets: string[];
|
|
88
92
|
apiOnly: boolean;
|
|
89
93
|
endpoints: Record<string, string>;
|
|
@@ -113,6 +117,7 @@ export declare const EDConfigSchema: z.ZodObject<{
|
|
|
113
117
|
endpoints: Record<string, string>;
|
|
114
118
|
plugins?: "proxy" | "remote" | undefined;
|
|
115
119
|
enabled?: boolean | undefined;
|
|
120
|
+
admin?: "hide" | "proxy" | undefined;
|
|
116
121
|
themeAssets?: string[] | undefined;
|
|
117
122
|
apiOnly?: boolean | undefined;
|
|
118
123
|
defaultRevalidate?: number | undefined;
|
|
@@ -37,12 +37,15 @@ export const EDConfigSchema = z.object({
|
|
|
37
37
|
.enum(["proxy", "remote"])
|
|
38
38
|
.default("remote")
|
|
39
39
|
.describe("Whether to proxy plugin assets or serve them from the serverless endpoint.\nDefault is `remote`, but `proxy` can be used to hide the CMS origin."),
|
|
40
|
-
|
|
40
|
+
admin: z
|
|
41
|
+
.enum(["proxy", "hide"])
|
|
42
|
+
.default("proxy")
|
|
43
|
+
.describe("How to handle the WordPress admin URLs.\nDefault is `proxy`, which will proxy the admin URLs to the CMS origin. When set to `hide`, all /wp-admin, /wp-json and /wp-login.php URLs will show a 404 page.\nHas no effect in dev mode."),
|
|
41
44
|
themeAssets: z
|
|
42
45
|
.array(z.string())
|
|
43
46
|
.optional()
|
|
44
47
|
.default(["assets"])
|
|
45
|
-
.describe('
|
|
48
|
+
.describe('Asset folders to include in a serverless deployment.\nDefault is `["assets"]`'),
|
|
46
49
|
apiOnly: z.boolean().optional().default(false).describe("Whether to deploy only the API, not the frontend"),
|
|
47
50
|
endpoints: z
|
|
48
51
|
.record(z.string(), z.string())
|