bun-plugin-stx 0.2.372 → 0.2.374
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.d.ts +2 -0
- package/dist/serve.js +14 -6
- package/package.json +3 -3
package/dist/serve.d.ts
CHANGED
|
@@ -335,6 +335,8 @@ export declare interface ServeOptions {
|
|
|
335
335
|
watchDirs?: string[]
|
|
336
336
|
renderCache?: boolean
|
|
337
337
|
renderCacheVary?: 'request' | 'source'
|
|
338
|
+
renderCacheLimit?: number
|
|
339
|
+
clientAddress?: (req: Request, server: ServeServer) => string | null | undefined
|
|
338
340
|
cssCacheLimit?: number
|
|
339
341
|
prewarmRenderCache?: boolean | number
|
|
340
342
|
imageWarmupGraceMs?: number
|
package/dist/serve.js
CHANGED
|
@@ -9323,7 +9323,7 @@ After installing: bun add bun-plugin-stx`);
|
|
|
9323
9323
|
const isExcludedPage = pageExcluder(options.exclude);
|
|
9324
9324
|
let discoveredPagePaths = null;
|
|
9325
9325
|
let assetsInitialized = false;
|
|
9326
|
-
const htmlCache =
|
|
9326
|
+
const htmlCache = boundedCache(options.renderCacheLimit ?? 512);
|
|
9327
9327
|
const ENABLE_HTML_CACHE = options.renderCache === true;
|
|
9328
9328
|
const RENDER_CACHE_VARY = options.renderCacheVary ?? "request";
|
|
9329
9329
|
const cssCssCache = boundedCache(options.cssCacheLimit ?? 512);
|
|
@@ -9667,6 +9667,14 @@ function __stxOverlay(errs){
|
|
|
9667
9667
|
full.responseHeaders = { ...full.responseHeaders, [header]: String(value) };
|
|
9668
9668
|
};
|
|
9669
9669
|
}
|
|
9670
|
+
function resolveClientAddress(req, server) {
|
|
9671
|
+
try {
|
|
9672
|
+
const address = options.clientAddress ? options.clientAddress(req, server) : server.requestIP(req)?.address;
|
|
9673
|
+
return address ?? "";
|
|
9674
|
+
} catch {
|
|
9675
|
+
return "";
|
|
9676
|
+
}
|
|
9677
|
+
}
|
|
9670
9678
|
function htmlCacheKey(filePath, reqCtx) {
|
|
9671
9679
|
if (RENDER_CACHE_VARY === "source")
|
|
9672
9680
|
return filePath;
|
|
@@ -10005,7 +10013,7 @@ function __stxOverlay(errs){
|
|
|
10005
10013
|
const isMutating = !!reqCtx && reqCtx.method !== "GET" && reqCtx.method !== "HEAD";
|
|
10006
10014
|
if (ENABLE_HTML_CACHE && !skipCacheHint && !isMutating) {
|
|
10007
10015
|
const cacheKey = htmlCacheKey(filePath, reqCtx);
|
|
10008
|
-
const cachedEntry = htmlCache.
|
|
10016
|
+
const cachedEntry = htmlCache.read(cacheKey);
|
|
10009
10017
|
if (cachedEntry && await templateSignatureFresh(cachedEntry.signature)) {
|
|
10010
10018
|
if (reqCtx) {
|
|
10011
10019
|
reqCtx.responseStatus = cachedEntry.status;
|
|
@@ -10082,7 +10090,7 @@ function __stxOverlay(errs){
|
|
|
10082
10090
|
}
|
|
10083
10091
|
if (ENABLE_HTML_CACHE && !context.__stx_skip_cache && !skipCacheHint && !isMutating && isRenderableCacheCandidate(output) && placeholdersAreReady) {
|
|
10084
10092
|
const signature = await buildTemplateSignature(filePath, dependencies);
|
|
10085
|
-
htmlCache.
|
|
10093
|
+
htmlCache.remember(htmlCacheKey(filePath, reqCtx), { html: output, signature, status: reqCtx?.responseStatus ?? 200, headers: reqCtx?.responseHeaders });
|
|
10086
10094
|
}
|
|
10087
10095
|
return output;
|
|
10088
10096
|
}
|
|
@@ -10204,7 +10212,7 @@ function __stxOverlay(errs){
|
|
|
10204
10212
|
if (reqCtx)
|
|
10205
10213
|
reqCtx.params = paramsObj;
|
|
10206
10214
|
if (cacheShell) {
|
|
10207
|
-
const cachedEntry = htmlCache.
|
|
10215
|
+
const cachedEntry = htmlCache.read(filePath);
|
|
10208
10216
|
if (cachedEntry && await templateSignatureFresh(cachedEntry.signature)) {
|
|
10209
10217
|
if (reqCtx) {
|
|
10210
10218
|
reqCtx.responseStatus = cachedEntry.status;
|
|
@@ -10285,7 +10293,7 @@ ${output}`;
|
|
|
10285
10293
|
const recordedResponse = readResponseStatus(context) !== undefined || !!readResponseHeaders(context);
|
|
10286
10294
|
if (!context.__stx_skip_cache && !recordedResponse && isRenderableCacheCandidate(output) && placeholdersAreReady) {
|
|
10287
10295
|
const signature = await buildTemplateSignature(filePath, dependencies);
|
|
10288
|
-
htmlCache.
|
|
10296
|
+
htmlCache.remember(filePath, { html: output, signature, status: reqCtx?.responseStatus ?? 200, headers: reqCtx?.responseHeaders });
|
|
10289
10297
|
}
|
|
10290
10298
|
return fillRouteParams(output, paramsObj);
|
|
10291
10299
|
}
|
|
@@ -10506,7 +10514,7 @@ ${block}`;
|
|
|
10506
10514
|
activeServeHost = req.headers.get("host") || "";
|
|
10507
10515
|
activeServeCookieHeader = req.headers.get("cookie") || "";
|
|
10508
10516
|
activeServeCookies = parseCookies(req);
|
|
10509
|
-
activeServeIp =
|
|
10517
|
+
activeServeIp = resolveClientAddress(req, server);
|
|
10510
10518
|
mintedCsrfToken = csrfTokenToMint(req, activeServeCookies);
|
|
10511
10519
|
if (mintedCsrfToken)
|
|
10512
10520
|
activeServeCookies[CSRF_COOKIE] = mintedCsrfToken;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-stx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.374",
|
|
5
5
|
"description": "A Bun plugin that allows for using Laravel Blade-like syntax.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"typecheck": "bun tsc --noEmit"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@stacksjs/stx": "0.2.
|
|
78
|
-
"stx-router": "0.2.
|
|
77
|
+
"@stacksjs/stx": "0.2.374",
|
|
78
|
+
"stx-router": "0.2.374"
|
|
79
79
|
}
|
|
80
80
|
}
|