bun-plugin-stx 0.2.103 → 0.2.105

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 CHANGED
@@ -17,6 +17,24 @@ export declare function buildDynamicRouteRegexes(fileRouteBase: string): RegExp[
17
17
  * `NODE_ENV=development`, so it keeps the helpful list.
18
18
  */
19
19
  export declare function isProductionServe(): boolean;
20
+ /**
21
+ * `Cache-Control` for a file served straight out of `publicDir`.
22
+ *
23
+ * Development says `no-store`, so a swapped favicon or hero image appears on
24
+ * the next reload rather than an hour later.
25
+ *
26
+ * Production does not: this server IS production for a server-rendered deploy,
27
+ * with no CDN in front stamping cache headers on the way past. Sending
28
+ * `no-store` there told every browser, proxy and link-preview crawler to
29
+ * re-fetch every image on every request, and made messengers that cache a
30
+ * preview by its headers throw the card away.
31
+ *
32
+ * An hour for ordinary assets, because they are replaced in place by a deploy
33
+ * and a share card that changed with a copy edit should not be stale for a
34
+ * year. A fingerprinted name (a content hash in it) can never change under a
35
+ * given URL, so it gets the long immutable lifetime.
36
+ */
37
+ export declare function staticCacheControl(pathname: string, production?: boolean): string;
20
38
  /**
21
39
  * Render the built-in fallback 404 page.
22
40
  *
@@ -98,6 +116,11 @@ export declare interface ServeOptions {
98
116
  | null
99
117
  | undefined
100
118
  | Promise<Response | Record<string, unknown> | null | undefined>
119
+ onResponse?: (req: Request, response: Response) =>
120
+ | Response
121
+ | null
122
+ | undefined
123
+ | Promise<Response | null | undefined>
101
124
  middleware?: Record<string, MiddlewareHandler>
102
125
  globalMiddleware?: string[]
103
126
  middlewareGroups?: Record<string, string[]>
package/dist/serve.js CHANGED
@@ -8726,6 +8726,12 @@ function isProductionServe() {
8726
8726
  const devEnvs = new Set(["development", "dev", "local", "test", "testing"]);
8727
8727
  return !(devEnvs.has(node) || devEnvs.has(app));
8728
8728
  }
8729
+ function staticCacheControl(pathname, production = isProductionServe()) {
8730
+ if (!production)
8731
+ return "no-store";
8732
+ const fingerprinted = /[.-][0-9a-f]{8,}\.[a-z0-9]+$/i.test(pathname);
8733
+ return fingerprinted ? "public, max-age=31536000, immutable" : "public, max-age=3600";
8734
+ }
8729
8735
  function render404Page(opts) {
8730
8736
  const { path, routes = [], isProduction } = opts;
8731
8737
  const baseStyles = `
@@ -10263,7 +10269,7 @@ ${pageSetupScripts.join(`
10263
10269
  return new Response(file, {
10264
10270
  headers: {
10265
10271
  "Content-Type": staticContentTypes[ext || ""] || "application/octet-stream",
10266
- "Cache-Control": "no-store"
10272
+ "Cache-Control": staticCacheControl(resolvedPath)
10267
10273
  }
10268
10274
  });
10269
10275
  }
@@ -10321,7 +10327,13 @@ ${pageSetupScripts.join(`
10321
10327
  activeServeIp = "";
10322
10328
  }
10323
10329
  })();
10324
- return applyI18nToResponse(_i18nResp, i18nLocale ?? (i18nConfig?.defaultLocale ?? "en"), path);
10330
+ const _finalResp = await applyI18nToResponse(_i18nResp, i18nLocale ?? (i18nConfig?.defaultLocale ?? "en"), path);
10331
+ if (options.onResponse) {
10332
+ const hooked = await options.onResponse(req, _finalResp);
10333
+ if (hooked instanceof Response)
10334
+ return hooked;
10335
+ }
10336
+ return _finalResp;
10325
10337
  }
10326
10338
  });
10327
10339
  break;
@@ -10399,6 +10411,7 @@ if (import.meta.main) {
10399
10411
  main().catch(console.error);
10400
10412
  }
10401
10413
  export {
10414
+ staticCacheControl,
10402
10415
  serve,
10403
10416
  render404Page,
10404
10417
  isProductionServe,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.103",
4
+ "version": "0.2.105",
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",