bun-plugin-stx 0.2.73 → 0.2.74
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/serve.js +39 -6
- package/package.json +1 -1
package/dist/serve.js
CHANGED
|
@@ -9018,6 +9018,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9018
9018
|
const extraProtectedPrefixes = authConfig?.protectedPaths ?? [];
|
|
9019
9019
|
let activeServeLocale = null;
|
|
9020
9020
|
let activeServeSearch = "";
|
|
9021
|
+
let activeServeHost = "";
|
|
9021
9022
|
function injectServeLocaleContext(context) {
|
|
9022
9023
|
if (!activeServeLocale)
|
|
9023
9024
|
return;
|
|
@@ -9029,17 +9030,20 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9029
9030
|
};
|
|
9030
9031
|
}
|
|
9031
9032
|
function injectServeRequestContext(context) {
|
|
9032
|
-
if (
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9033
|
+
if (activeServeSearch) {
|
|
9034
|
+
context.__stxServeSearch = activeServeSearch;
|
|
9035
|
+
globalThis.__stxServeSearch = activeServeSearch;
|
|
9036
|
+
}
|
|
9037
|
+
if (activeServeHost)
|
|
9038
|
+
context.host = activeServeHost;
|
|
9036
9039
|
}
|
|
9037
9040
|
function htmlCacheKey(filePath) {
|
|
9038
9041
|
const loc = i18nConfig ? activeServeLocale ?? i18nConfig.defaultLocale : "";
|
|
9039
9042
|
const search = activeServeSearch || "";
|
|
9040
|
-
|
|
9043
|
+
const host = activeServeHost || "";
|
|
9044
|
+
if (!loc && !search && !host)
|
|
9041
9045
|
return filePath;
|
|
9042
|
-
return `${filePath}\x00${loc}\x00${search}`;
|
|
9046
|
+
return `${filePath}\x00${loc}\x00${search}\x00${host}`;
|
|
9043
9047
|
}
|
|
9044
9048
|
const builtInMiddleware = authConfig === null ? {} : {
|
|
9045
9049
|
auth: (_req, ctx) => {
|
|
@@ -9354,6 +9358,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9354
9358
|
app: stxConfig.app || {},
|
|
9355
9359
|
..."strict" in stxConfig && { strict: stxConfig.strict },
|
|
9356
9360
|
..."router" in stxConfig && { router: stxConfig.router },
|
|
9361
|
+
..."debug" in stxConfig && { debug: stxConfig.debug },
|
|
9357
9362
|
..."skipDefaultSeoTags" in stxConfig && { skipDefaultSeoTags: stxConfig.skipDefaultSeoTags },
|
|
9358
9363
|
..."defaultTitle" in stxConfig && { defaultTitle: stxConfig.defaultTitle },
|
|
9359
9364
|
..."defaultDescription" in stxConfig && { defaultDescription: stxConfig.defaultDescription },
|
|
@@ -9521,6 +9526,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9521
9526
|
app: stxConfig.app || {},
|
|
9522
9527
|
..."strict" in stxConfig && { strict: stxConfig.strict },
|
|
9523
9528
|
..."router" in stxConfig && { router: stxConfig.router },
|
|
9529
|
+
..."debug" in stxConfig && { debug: stxConfig.debug },
|
|
9524
9530
|
..."skipDefaultSeoTags" in stxConfig && { skipDefaultSeoTags: stxConfig.skipDefaultSeoTags },
|
|
9525
9531
|
..."defaultTitle" in stxConfig && { defaultTitle: stxConfig.defaultTitle },
|
|
9526
9532
|
..."defaultDescription" in stxConfig && { defaultDescription: stxConfig.defaultDescription },
|
|
@@ -9679,6 +9685,31 @@ ${html}`;
|
|
|
9679
9685
|
async fetch(req) {
|
|
9680
9686
|
const url = new URL(req.url);
|
|
9681
9687
|
let path = url.pathname;
|
|
9688
|
+
const proxyRules = stxConfig.server?.proxy;
|
|
9689
|
+
if (proxyRules) {
|
|
9690
|
+
for (const [prefix, rule] of Object.entries(proxyRules)) {
|
|
9691
|
+
if (path !== prefix && !path.startsWith(prefix))
|
|
9692
|
+
continue;
|
|
9693
|
+
const ruleCfg = typeof rule === "string" ? { target: rule } : rule;
|
|
9694
|
+
const outPath = ruleCfg.rewrite ? ruleCfg.rewrite(path) : path;
|
|
9695
|
+
const target = new URL(ruleCfg.target);
|
|
9696
|
+
const outUrl = new URL(outPath + url.search, target);
|
|
9697
|
+
const headers = new Headers(req.headers);
|
|
9698
|
+
if (ruleCfg.changeOrigin !== false)
|
|
9699
|
+
headers.set("host", target.host);
|
|
9700
|
+
try {
|
|
9701
|
+
return await fetch(outUrl, {
|
|
9702
|
+
method: req.method,
|
|
9703
|
+
headers,
|
|
9704
|
+
body: req.body,
|
|
9705
|
+
redirect: "manual",
|
|
9706
|
+
...req.body ? { duplex: "half" } : {}
|
|
9707
|
+
});
|
|
9708
|
+
} catch (err) {
|
|
9709
|
+
return new Response(`[stx dev proxy] ${prefix} \u2192 ${ruleCfg.target} failed: ${err instanceof Error ? err.message : String(err)}`, { status: 502 });
|
|
9710
|
+
}
|
|
9711
|
+
}
|
|
9712
|
+
}
|
|
9682
9713
|
let i18nLocale = null;
|
|
9683
9714
|
if (i18nConfig && !url.pathname.startsWith("/api/")) {
|
|
9684
9715
|
const stripped = localeFromPath(url.pathname);
|
|
@@ -9699,6 +9730,7 @@ ${html}`;
|
|
|
9699
9730
|
const _i18nResp = await (async () => {
|
|
9700
9731
|
activeServeLocale = i18nLocale;
|
|
9701
9732
|
activeServeSearch = url.search;
|
|
9733
|
+
activeServeHost = req.headers.get("host") || "";
|
|
9702
9734
|
try {
|
|
9703
9735
|
if (req.method === "OPTIONS") {
|
|
9704
9736
|
return new Response(null, { headers: corsHeaders });
|
|
@@ -10134,6 +10166,7 @@ ${pageSetupScripts.join(`
|
|
|
10134
10166
|
} finally {
|
|
10135
10167
|
activeServeLocale = null;
|
|
10136
10168
|
activeServeSearch = "";
|
|
10169
|
+
activeServeHost = "";
|
|
10137
10170
|
}
|
|
10138
10171
|
})();
|
|
10139
10172
|
return applyI18nToResponse(_i18nResp, i18nLocale ?? (i18nConfig?.defaultLocale ?? "en"), path);
|
package/package.json
CHANGED