@rangojs/router 0.0.0-experimental.118 → 0.0.0-experimental.119

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.
@@ -2130,7 +2130,7 @@ import { resolve } from "node:path";
2130
2130
  // package.json
2131
2131
  var package_default = {
2132
2132
  name: "@rangojs/router",
2133
- version: "0.0.0-experimental.118",
2133
+ version: "0.0.0-experimental.119",
2134
2134
  description: "Django-inspired RSC router with composable URL patterns",
2135
2135
  keywords: [
2136
2136
  "react",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rangojs/router",
3
- "version": "0.0.0-experimental.118",
3
+ "version": "0.0.0-experimental.119",
4
4
  "description": "Django-inspired RSC router with composable URL patterns",
5
5
  "keywords": [
6
6
  "react",
@@ -249,7 +249,7 @@ export class CFCacheStore<TEnv = unknown> implements SegmentCacheStore<TEnv> {
249
249
  ) => string | Promise<string>;
250
250
 
251
251
  private readonly namespace?: string;
252
- private readonly baseUrl: string;
252
+ private readonly explicitBaseUrl?: string;
253
253
  private readonly waitUntil?: (fn: () => Promise<void>) => void;
254
254
  private readonly version?: string;
255
255
  private readonly kv?: KVNamespace;
@@ -264,7 +264,12 @@ export class CFCacheStore<TEnv = unknown> implements SegmentCacheStore<TEnv> {
264
264
  }
265
265
 
266
266
  this.namespace = options.namespace;
267
- this.baseUrl = options.baseUrl ?? this.deriveBaseUrl();
267
+ // Base URL is resolved lazily per cache operation (see resolveBaseUrl).
268
+ // The store is constructed before the per-request context ALS is entered
269
+ // (the cache factory runs ahead of runWithRequestContext in the handler),
270
+ // so deriving the host here would always miss the request and fall back to
271
+ // the internal host. Only the explicit override can be captured eagerly.
272
+ this.explicitBaseUrl = options.baseUrl;
268
273
  this.defaults = options.defaults;
269
274
  this.version = options.version ?? VERSION;
270
275
  this.keyGenerator = options.keyGenerator;
@@ -272,9 +277,22 @@ export class CFCacheStore<TEnv = unknown> implements SegmentCacheStore<TEnv> {
272
277
  this.kv = options.kv;
273
278
  }
274
279
 
280
+ /**
281
+ * Resolve the cache-key base URL for the current cache operation.
282
+ * Prefers an explicit `baseUrl` option; otherwise derives it from the live
283
+ * request. Called per operation (from keyToRequest), which runs inside the
284
+ * request-context ALS, so deriveBaseUrl sees the request and can use the
285
+ * production host instead of the internal fallback.
286
+ * @internal
287
+ */
288
+ private resolveBaseUrl(): string {
289
+ return this.explicitBaseUrl ?? this.deriveBaseUrl();
290
+ }
291
+
275
292
  /**
276
293
  * Derive base URL from request hostname via requestContext.
277
294
  * Uses internal fallback for dev/preview environments and untrusted hostnames.
295
+ * Must run inside the request context (invoked lazily via resolveBaseUrl).
278
296
  * @internal
279
297
  */
280
298
  private deriveBaseUrl(): string {
@@ -743,7 +761,7 @@ export class CFCacheStore<TEnv = unknown> implements SegmentCacheStore<TEnv> {
743
761
  const encodedKey = encodeURIComponent(key);
744
762
  // Include version in URL path to invalidate cache when version changes
745
763
  const versionPath = this.version ? `v/${this.version}/` : "";
746
- return new Request(`${this.baseUrl}${versionPath}${encodedKey}`, {
764
+ return new Request(`${this.resolveBaseUrl()}${versionPath}${encodedKey}`, {
747
765
  method: "GET",
748
766
  });
749
767
  }