eddev 2.0.0-beta.70 → 2.0.0-beta.71
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/server/proxy-wp-admin.js +3 -6
- package/dist/app/server/render-ssr-page.d.ts +1 -0
- package/dist/app/server/render-ssr-page.js +1 -0
- package/dist/app/server/server-context.d.ts +4 -1
- package/dist/app/server/server-context.js +11 -4
- package/dist/app/server/utils/replace-host.d.ts +1 -1
- package/dist/app/server/utils/replace-host.js +11 -2
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/vinxi-app.js +14 -0
- package/dist/node/compiler/vinxi-codegen.js +7 -3
- package/package.json +1 -1
|
@@ -5,7 +5,6 @@ import { ServerContext } from "./server-context.js";
|
|
|
5
5
|
import { renderErrorPage } from "./render-ssr-page.js";
|
|
6
6
|
export async function proxyWpAdmin(event) {
|
|
7
7
|
const serverContext = ServerContext.main;
|
|
8
|
-
const replaceUrls = serverContext.replaceUrls;
|
|
9
8
|
const req = getWebRequest(event);
|
|
10
9
|
const reqUrl = getRequestURL(event);
|
|
11
10
|
const serverlessConfig = serverContext.config.serverless;
|
|
@@ -46,8 +45,8 @@ export async function proxyWpAdmin(event) {
|
|
|
46
45
|
cookies.push(...splitSetCookieString(value));
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
|
-
if (key === "location"
|
|
50
|
-
value = replaceUrls(value);
|
|
48
|
+
if (key === "location") {
|
|
49
|
+
value = serverContext.replaceUrls(value);
|
|
51
50
|
}
|
|
52
51
|
res.headers.set(key, value);
|
|
53
52
|
});
|
|
@@ -61,9 +60,7 @@ export async function proxyWpAdmin(event) {
|
|
|
61
60
|
// Replace URLs pointing to the origin server from the response itself
|
|
62
61
|
// This is only done for text-based content types, like application/json, text/plain, text/html etc
|
|
63
62
|
if (contentType?.match(/(application|text)\//)) {
|
|
64
|
-
|
|
65
|
-
body = replaceUrls((await response.text()) ?? "");
|
|
66
|
-
}
|
|
63
|
+
body = serverContext.replaceUrls((await response.text()) ?? "", reqUrl.origin);
|
|
67
64
|
// If the content type is text/html, inject the Vite assets into the response — assuming the placeholder comments are found
|
|
68
65
|
if (contentType.startsWith("text/html")) {
|
|
69
66
|
const clientManifest = serverContext.runtime.getManifest("admin");
|
|
@@ -7,6 +7,7 @@ export declare function getSsrStream(args: SSRArgs): Promise<ReadableStream<Uint
|
|
|
7
7
|
type RenderArgs = {
|
|
8
8
|
pathname: string;
|
|
9
9
|
statusCode?: number;
|
|
10
|
+
newOrigin?: string;
|
|
10
11
|
};
|
|
11
12
|
export declare function renderPage(args: RenderArgs): Promise<Response>;
|
|
12
13
|
type RenderErrorPageArgs = {
|
|
@@ -23,22 +23,25 @@ type ServerAppData = {
|
|
|
23
23
|
export declare class ServerContext {
|
|
24
24
|
dev: boolean;
|
|
25
25
|
origin: string;
|
|
26
|
-
|
|
26
|
+
_urlReplacer?: (text: string, origin?: string) => string;
|
|
27
27
|
rpcBases: string[];
|
|
28
28
|
config: EDConfig;
|
|
29
29
|
static main: ServerContext;
|
|
30
30
|
constructor(conf: ServerContextArgs);
|
|
31
|
+
replaceUrls(text: string, origin?: string): string;
|
|
31
32
|
get runtime(): ServerContextRuntime;
|
|
32
33
|
static setRuntime(rt: ServerContextRuntime): void;
|
|
33
34
|
getOriginUrl(url: string): string;
|
|
34
35
|
fetchOrigin(url: string, opts?: RequestInit & {
|
|
35
36
|
replaceUrls?: boolean;
|
|
37
|
+
newOrigin?: string;
|
|
36
38
|
}): Promise<Response>;
|
|
37
39
|
fetchRouteData(req: {
|
|
38
40
|
pathname: string;
|
|
39
41
|
query?: Record<string, any>;
|
|
40
42
|
headers?: RequestHeaders;
|
|
41
43
|
withAppData?: boolean;
|
|
44
|
+
newOrigin?: string;
|
|
42
45
|
}): Promise<Response>;
|
|
43
46
|
fetchAppData(): Promise<ServerAppData>;
|
|
44
47
|
extractRequestHeaders(req?: RequestHeaders): Partial<Record<import("vinxi/http").HTTPHeaderName, string | undefined>>;
|
|
@@ -17,7 +17,7 @@ let runtime;
|
|
|
17
17
|
export class ServerContext {
|
|
18
18
|
dev;
|
|
19
19
|
origin;
|
|
20
|
-
|
|
20
|
+
_urlReplacer;
|
|
21
21
|
rpcBases = [];
|
|
22
22
|
config;
|
|
23
23
|
static main;
|
|
@@ -27,10 +27,16 @@ export class ServerContext {
|
|
|
27
27
|
this.rpcBases = conf.rpcBases ?? [];
|
|
28
28
|
this.config = conf.config;
|
|
29
29
|
if (conf.replaceUrls) {
|
|
30
|
-
this.
|
|
30
|
+
this._urlReplacer = createUrlReplacer(conf.replaceUrls);
|
|
31
31
|
}
|
|
32
32
|
ServerContext.main = this;
|
|
33
33
|
}
|
|
34
|
+
replaceUrls(text, origin) {
|
|
35
|
+
if (this._urlReplacer) {
|
|
36
|
+
return this._urlReplacer(text, origin);
|
|
37
|
+
}
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
34
40
|
get runtime() {
|
|
35
41
|
return runtime;
|
|
36
42
|
}
|
|
@@ -66,8 +72,8 @@ export class ServerContext {
|
|
|
66
72
|
});
|
|
67
73
|
// console.log("Returning headers", headers)
|
|
68
74
|
let text = await response.text();
|
|
69
|
-
if (opts?.replaceUrls
|
|
70
|
-
text = this.replaceUrls(text);
|
|
75
|
+
if (opts?.replaceUrls) {
|
|
76
|
+
text = this.replaceUrls(text, opts.newOrigin);
|
|
71
77
|
}
|
|
72
78
|
return new Response(text, {
|
|
73
79
|
status: response.status,
|
|
@@ -86,6 +92,7 @@ export class ServerContext {
|
|
|
86
92
|
const result = await this.fetchOrigin(fetchUrl, {
|
|
87
93
|
cache: "no-cache",
|
|
88
94
|
replaceUrls: true,
|
|
95
|
+
newOrigin: req.newOrigin,
|
|
89
96
|
headers: {
|
|
90
97
|
"Content-Type": "application/json",
|
|
91
98
|
Accept: "application/json",
|
|
@@ -2,7 +2,7 @@ export function createUrlReplacer(conf) {
|
|
|
2
2
|
// Create a regular expression to match the URL
|
|
3
3
|
// Note that that the regex doesn't necessarily match the entire URL
|
|
4
4
|
const lookup = new RegExp(conf.from.replace(/https?[:\\\/]+/, "https?[:\\/\\\\]+") + "([a-z0-9\\-_/\\\\]+)", "ig");
|
|
5
|
-
return (text) => {
|
|
5
|
+
return (text, newOrigin) => {
|
|
6
6
|
return text.replace(lookup, (url) => {
|
|
7
7
|
// Strip out the origin, to create a relative path
|
|
8
8
|
const path = url.replace(/https?:[\/\\]+[^\/\\]+/, "");
|
|
@@ -18,10 +18,19 @@ export function createUrlReplacer(conf) {
|
|
|
18
18
|
return url;
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
|
|
21
|
+
break;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
console.log("Replacing", url, "with", newOrigin);
|
|
26
|
+
if (newOrigin) {
|
|
27
|
+
if (isEscaped) {
|
|
28
|
+
return newOrigin.replace(/\//g, "\\/") + path;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return newOrigin + path;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
25
34
|
return path;
|
|
26
35
|
// if (path.startsWith("/wp-content/uploads/")) {
|
|
27
36
|
// if (!conf.ignoreUploads) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.71";
|
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.71";
|
|
@@ -33,6 +33,20 @@ export function createVinxiApp(args) {
|
|
|
33
33
|
varies: [],
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
|
+
"/robots.txt": {
|
|
37
|
+
proxy: joinURL(args.origin, "robots.txt"),
|
|
38
|
+
static: true,
|
|
39
|
+
cache: {
|
|
40
|
+
maxAge: 3600,
|
|
41
|
+
varies: [],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
"/sitemap*.xml": {
|
|
45
|
+
cache: {
|
|
46
|
+
maxAge: 3600,
|
|
47
|
+
swr: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
36
50
|
"/wp-content/plugins/**": {
|
|
37
51
|
proxy: joinURL(args.origin, "wp-content/plugins/**"),
|
|
38
52
|
headers: {
|
|
@@ -20,7 +20,7 @@ export function createVinxiCodegen(opts) {
|
|
|
20
20
|
name: "context.ts",
|
|
21
21
|
generate: async () => {
|
|
22
22
|
const args = {
|
|
23
|
-
dev:
|
|
23
|
+
dev: opts.mode === "development",
|
|
24
24
|
origin: project.origin,
|
|
25
25
|
replaceUrls: {
|
|
26
26
|
from: project.origin,
|
|
@@ -181,7 +181,7 @@ export function createVinxiCodegen(opts) {
|
|
|
181
181
|
name: "handler.data-api.ts",
|
|
182
182
|
generate: code /* tsx */ `
|
|
183
183
|
/// <reference types="vinxi/types/server" />
|
|
184
|
-
import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders } from "vinxi/http"
|
|
184
|
+
import { createRouter, eventHandler, getRouterParam, getQuery, getWebRequest, getRequestHeaders, getRequestURL } from "vinxi/http"
|
|
185
185
|
import { serverContext } from "./context.js"
|
|
186
186
|
|
|
187
187
|
const router = createRouter()
|
|
@@ -189,10 +189,12 @@ export function createVinxiCodegen(opts) {
|
|
|
189
189
|
"/route/",
|
|
190
190
|
eventHandler(async (event) => {
|
|
191
191
|
const id = "/"
|
|
192
|
+
const url = getRequestURL(event);
|
|
192
193
|
|
|
193
194
|
return await serverContext.fetchRouteData({
|
|
194
195
|
pathname: id,
|
|
195
196
|
withAppData: false,
|
|
197
|
+
newOrigin: url.origin,
|
|
196
198
|
})
|
|
197
199
|
}),
|
|
198
200
|
)
|
|
@@ -200,10 +202,12 @@ export function createVinxiCodegen(opts) {
|
|
|
200
202
|
"/route/**:name",
|
|
201
203
|
eventHandler(async (event) => {
|
|
202
204
|
const id = "/" + getRouterParam(event, "name")
|
|
205
|
+
const url = getRequestURL(event);
|
|
203
206
|
|
|
204
207
|
return await serverContext.fetchRouteData({
|
|
205
208
|
pathname: id,
|
|
206
209
|
withAppData: false,
|
|
210
|
+
newOrigin: url.origin,
|
|
207
211
|
})
|
|
208
212
|
}),
|
|
209
213
|
)
|
|
@@ -268,7 +272,7 @@ export function createVinxiCodegen(opts) {
|
|
|
268
272
|
return proxyWpAdmin(event)
|
|
269
273
|
}
|
|
270
274
|
|
|
271
|
-
return renderPage({ pathname: url.pathname })
|
|
275
|
+
return renderPage({ pathname: url.pathname, newOrigin: url.origin })
|
|
272
276
|
}
|
|
273
277
|
})
|
|
274
278
|
`,
|