@witchcraft/nuxt-electron 0.4.1 → 0.4.2
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/module.json
CHANGED
|
@@ -50,7 +50,7 @@ routeProxies: Record<string, string | {
|
|
|
50
50
|
url: never;
|
|
51
51
|
convertPath: never;
|
|
52
52
|
ignore: true;
|
|
53
|
-
}>, { logger, errorPage, session, proxiedProperties }?: {
|
|
53
|
+
}>, { logger, errorPage, session, modifyRequest, proxiedProperties }?: {
|
|
54
54
|
/**
|
|
55
55
|
* Optional logger. It's suggested you not pass this unless you're traceging in dev mode as a lot of requests can be made.
|
|
56
56
|
*/
|
|
@@ -72,5 +72,6 @@ routeProxies: Record<string, string | {
|
|
|
72
72
|
session?: Session;
|
|
73
73
|
/** Request properties forwarded to the proxied request. The url is always replaced. */
|
|
74
74
|
proxiedProperties?: (keyof Request)[];
|
|
75
|
+
modifyRequest?: (init: RequestInit, url: string) => RequestInit;
|
|
75
76
|
}): void;
|
|
76
77
|
export {};
|
|
@@ -68,6 +68,7 @@ export function createProxiedProtocolHandler(protocol, protocolName = "app", bas
|
|
|
68
68
|
logger,
|
|
69
69
|
errorPage = "404.html",
|
|
70
70
|
session,
|
|
71
|
+
modifyRequest,
|
|
71
72
|
proxiedProperties = [
|
|
72
73
|
"method",
|
|
73
74
|
"headers",
|
|
@@ -126,9 +127,16 @@ export function createProxiedProtocolHandler(protocol, protocolName = "app", bas
|
|
|
126
127
|
finalPath: cachedProxyResult
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
|
-
|
|
130
|
+
let init = pick(request, proxiedProperties);
|
|
130
131
|
if (init.body) init.duplex = "half";
|
|
131
|
-
|
|
132
|
+
const finalUrl = cachedProxyResult + parsedUrl.search;
|
|
133
|
+
const headers = new Headers(init.headers);
|
|
134
|
+
headers.set("origin", new URL(finalUrl).origin);
|
|
135
|
+
headers.set("referer", finalUrl);
|
|
136
|
+
headers.set("sec-fetch-site", "same-origin");
|
|
137
|
+
init.headers = headers;
|
|
138
|
+
if (modifyRequest) init = modifyRequest(init, finalUrl);
|
|
139
|
+
return netFetch(finalUrl, init);
|
|
132
140
|
}
|
|
133
141
|
const originalPath = path.join(basePath, requestPath);
|
|
134
142
|
const pathWithIndexHtml = path.join(originalPath, "index.html");
|
package/package.json
CHANGED
|
@@ -147,6 +147,7 @@ export function createProxiedProtocolHandler(
|
|
|
147
147
|
logger,
|
|
148
148
|
errorPage = "404.html",
|
|
149
149
|
session,
|
|
150
|
+
modifyRequest,
|
|
150
151
|
proxiedProperties = [
|
|
151
152
|
"method",
|
|
152
153
|
"headers",
|
|
@@ -185,6 +186,7 @@ export function createProxiedProtocolHandler(
|
|
|
185
186
|
session?: Session
|
|
186
187
|
/** Request properties forwarded to the proxied request. The url is always replaced. */
|
|
187
188
|
proxiedProperties?: (keyof Request)[]
|
|
189
|
+
modifyRequest?: (init: RequestInit, url: string) => RequestInit
|
|
188
190
|
|
|
189
191
|
} = {}
|
|
190
192
|
): void {
|
|
@@ -249,10 +251,17 @@ export function createProxiedProtocolHandler(
|
|
|
249
251
|
finalPath: cachedProxyResult
|
|
250
252
|
})
|
|
251
253
|
}
|
|
252
|
-
|
|
254
|
+
let init = pick(request, proxiedProperties) as RequestInit
|
|
253
255
|
// fetch rejects a streamed body unless the stream mode is declared
|
|
254
256
|
if (init.body) (init as any).duplex = "half"
|
|
255
|
-
|
|
257
|
+
const finalUrl = cachedProxyResult + parsedUrl.search
|
|
258
|
+
const headers = new Headers(init.headers)
|
|
259
|
+
headers.set("origin", new URL(finalUrl).origin)
|
|
260
|
+
headers.set("referer", finalUrl)
|
|
261
|
+
headers.set("sec-fetch-site", "same-origin")
|
|
262
|
+
init.headers = headers
|
|
263
|
+
if (modifyRequest) init = modifyRequest(init, finalUrl)
|
|
264
|
+
return netFetch(finalUrl, init)
|
|
256
265
|
}
|
|
257
266
|
|
|
258
267
|
const originalPath = path.join(basePath, requestPath)
|