bun-plugin-stx 0.2.74 → 0.2.75

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.
Files changed (2) hide show
  1. package/dist/serve.js +16 -3
  2. package/package.json +1 -1
package/dist/serve.js CHANGED
@@ -9019,6 +9019,9 @@ After installing: bun add bun-plugin-stx`);
9019
9019
  let activeServeLocale = null;
9020
9020
  let activeServeSearch = "";
9021
9021
  let activeServeHost = "";
9022
+ let activeServeCookies = {};
9023
+ let activeServeCookieHeader = "";
9024
+ let activeServeIp = "";
9022
9025
  function injectServeLocaleContext(context) {
9023
9026
  if (!activeServeLocale)
9024
9027
  return;
@@ -9036,14 +9039,18 @@ After installing: bun add bun-plugin-stx`);
9036
9039
  }
9037
9040
  if (activeServeHost)
9038
9041
  context.host = activeServeHost;
9042
+ context.cookies = activeServeCookies;
9043
+ if (activeServeIp)
9044
+ context.ip = activeServeIp;
9039
9045
  }
9040
9046
  function htmlCacheKey(filePath) {
9041
9047
  const loc = i18nConfig ? activeServeLocale ?? i18nConfig.defaultLocale : "";
9042
9048
  const search = activeServeSearch || "";
9043
9049
  const host = activeServeHost || "";
9044
- if (!loc && !search && !host)
9050
+ const cookies = activeServeCookieHeader;
9051
+ if (!loc && !search && !host && !cookies)
9045
9052
  return filePath;
9046
- return `${filePath}\x00${loc}\x00${search}\x00${host}`;
9053
+ return `${filePath}\x00${loc}\x00${search}\x00${host}\x00${cookies}`;
9047
9054
  }
9048
9055
  const builtInMiddleware = authConfig === null ? {} : {
9049
9056
  auth: (_req, ctx) => {
@@ -9682,7 +9689,7 @@ ${html}`;
9682
9689
  _server = bunServe({
9683
9690
  port: actualPort,
9684
9691
  idleTimeout: 0,
9685
- async fetch(req) {
9692
+ async fetch(req, server) {
9686
9693
  const url = new URL(req.url);
9687
9694
  let path = url.pathname;
9688
9695
  const proxyRules = stxConfig.server?.proxy;
@@ -9731,6 +9738,9 @@ ${html}`;
9731
9738
  activeServeLocale = i18nLocale;
9732
9739
  activeServeSearch = url.search;
9733
9740
  activeServeHost = req.headers.get("host") || "";
9741
+ activeServeCookieHeader = req.headers.get("cookie") || "";
9742
+ activeServeCookies = parseCookies(req);
9743
+ activeServeIp = server.requestIP(req)?.address || (req.headers.get("x-forwarded-for") || "").split(",")[0].trim();
9734
9744
  try {
9735
9745
  if (req.method === "OPTIONS") {
9736
9746
  return new Response(null, { headers: corsHeaders });
@@ -10167,6 +10177,9 @@ ${pageSetupScripts.join(`
10167
10177
  activeServeLocale = null;
10168
10178
  activeServeSearch = "";
10169
10179
  activeServeHost = "";
10180
+ activeServeCookieHeader = "";
10181
+ activeServeCookies = {};
10182
+ activeServeIp = "";
10170
10183
  }
10171
10184
  })();
10172
10185
  return applyI18nToResponse(_i18nResp, i18nLocale ?? (i18nConfig?.defaultLocale ?? "en"), path);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bun-plugin-stx",
3
3
  "type": "module",
4
- "version": "0.2.74",
4
+ "version": "0.2.75",
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",