@megabudino/stack-utils 1.0.0 → 1.1.0
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/proxy/handle.js +6 -1
- package/dist/proxy/types.d.ts +6 -0
- package/package.json +2 -1
package/dist/proxy/handle.js
CHANGED
|
@@ -11,6 +11,7 @@ export function createProxyHandle(config) {
|
|
|
11
11
|
const sitemapCache = `public, max-age=${config.sitemapCacheSeconds ?? 3600}`;
|
|
12
12
|
const proxyAssets = config.proxyAssets ?? false;
|
|
13
13
|
const additionalOrigins = config.additionalOrigins ?? [];
|
|
14
|
+
const textReplacements = config.textReplacements ?? {};
|
|
14
15
|
return async ({ event, resolve }) => {
|
|
15
16
|
const { pathname, search } = event.url;
|
|
16
17
|
if (event.route.id) {
|
|
@@ -75,7 +76,11 @@ export function createProxyHandle(config) {
|
|
|
75
76
|
}
|
|
76
77
|
if (contentType.includes('text/html')) {
|
|
77
78
|
const html = await upstreamResponse.text();
|
|
78
|
-
|
|
79
|
+
let result = rewriteHtml(html, originUrl, siteUrl, proxyAssets, additionalOrigins);
|
|
80
|
+
for (const [search, replace] of Object.entries(textReplacements)) {
|
|
81
|
+
result = result.replaceAll(search, replace);
|
|
82
|
+
}
|
|
83
|
+
return new Response(result, {
|
|
79
84
|
status: upstreamResponse.status,
|
|
80
85
|
statusText: upstreamResponse.statusText,
|
|
81
86
|
headers: cleanHeaders
|
package/dist/proxy/types.d.ts
CHANGED
|
@@ -25,4 +25,10 @@ export interface ProxyConfig {
|
|
|
25
25
|
* rewritten the same way as `originUrl` (e.g. legacy/migration domains).
|
|
26
26
|
*/
|
|
27
27
|
additionalOrigins?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Key-value map of text replacements applied to HTML responses
|
|
30
|
+
* after all standard URL rewrites. Each key is replaced with its value
|
|
31
|
+
* using `String.prototype.replaceAll`.
|
|
32
|
+
*/
|
|
33
|
+
textReplacements?: Record<string, string>;
|
|
28
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@megabudino/stack-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Reusable utilities for a SvelteKit stack, including a reverse proxy and static image pipeline",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "node ./scripts/build.mjs",
|
|
31
|
+
"test": "node --test proxy.test.mjs",
|
|
31
32
|
"typecheck": "tsc --noEmit"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|