@rsc-kit/core 0.43.0 → 0.44.0
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/headers.d.ts +2 -0
- package/dist/headers.js +2 -0
- package/dist/headers.js.map +1 -1
- package/dist/host.js +47 -29
- package/dist/host.js.map +1 -1
- package/dist/hostCalls.d.ts +6 -0
- package/dist/hostCalls.js +11 -1
- package/dist/hostCalls.js.map +1 -1
- package/dist/js/RouteErrorBoundary.js +1 -0
- package/dist/js/RouteErrorBoundary.js.map +1 -1
- package/dist/js/devErrorOverlay.d.ts +25 -0
- package/dist/js/devErrorOverlay.js +74 -2
- package/dist/js/devErrorOverlay.js.map +1 -1
- package/dist/manifest.d.ts +8 -0
- package/dist/manifest.js.map +1 -1
- package/dist/request.d.ts +16 -0
- package/dist/request.js +17 -0
- package/dist/request.js.map +1 -1
- package/dist/vite.d.ts +18 -0
- package/dist/vite.js +90 -4
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/headers.d.ts
CHANGED
|
@@ -43,6 +43,8 @@ export declare const HEADER: {
|
|
|
43
43
|
* instead leaves an upload undecodable.
|
|
44
44
|
*/
|
|
45
45
|
readonly contentType: 'X-RSC-Content-Type';
|
|
46
|
+
/** What every address below begins with: this package's own, on any host, whatever routes the app has. */
|
|
47
|
+
readonly endpoints: '/_rsc/';
|
|
46
48
|
/**
|
|
47
49
|
* Where the browser posts server actions.
|
|
48
50
|
*
|
package/dist/headers.js
CHANGED
|
@@ -52,6 +52,8 @@ export const HEADER = {
|
|
|
52
52
|
* instead leaves an upload undecodable.
|
|
53
53
|
*/
|
|
54
54
|
contentType: 'X-RSC-Content-Type',
|
|
55
|
+
/** What every address below begins with: this package's own, on any host, whatever routes the app has. */
|
|
56
|
+
endpoints: '/_rsc/',
|
|
55
57
|
/**
|
|
56
58
|
* Where the browser posts server actions.
|
|
57
59
|
*
|
package/dist/headers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
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MAAM,CAAC,UAAU;IACjB,MAAM,CAAC,SAAS;IAChB,MAAM,CAAC,OAAO;CACf,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAEZ;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,mBAAmB,CAAA;AAE7C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,oCAAoC,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,qCAAqC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,aAAa;IACvB,UAAU,EAAE,eAAe;IAC3B,QAAQ,EAAE,YAAY;IACtB,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,YAAY;IACnB;;;;OAIG;IACH,MAAM,EAAE,aAAa;IACrB,iFAAiF;IACjF,KAAK,EAAE,YAAY;IACnB,iFAAiF;IACjF,gBAAgB,EAAE,cAAc;IAChC,uEAAuE;IACvE,YAAY,EAAE,YAAY;CAClB,CAAA;AAEV;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,kBAAkB;IAClB,MAAM;IACN,eAAe;IACf,cAAc;IACd,yBAAyB;IACzB,qCAAqC;IACrC,oBAAoB;IACpB,iBAAiB;IACjB,2BAA2B;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,4BAA4B;IAC5B,8BAA8B;IAC9B,8BAA8B;IAC9B,wBAAwB;CAChB,CAAA","sourcesContent":["// The wire protocol, as names rather than string literals.\n//\n// A host writing these out by hand is how they drift. Two of them are not\n// negotiable at all — the client sends them or asks for them at fixed\n// addresses, and a host that spells one differently fails silently: the\n// request falls through, the decoder never runs, and a button does nothing\n// with no error on either side.\n//\n// PROTOCOL.md describes what each one means. This is the same list, importable.\n\nexport const HEADER = {\n /**\n * Present on a request for a Flight payload rather than the document. One\n * url serves both, which is why every answer must Vary on it.\n */\n rsc: 'X-RSC',\n\n /** The layout chain the client has mounted, outermost first, comma-separated. */\n segments: 'X-RSC-Segments',\n\n /** The boundary the answer replaces. 0 means a whole document. */\n segmentDepth: 'X-RSC-Segment-Depth',\n\n /** The chain to send back next time. */\n layouts: 'X-RSC-Layouts',\n\n /**\n * On a payload request: this url's page said it does not exist, after the\n * shell went out, and the client is asking for the not-found page to put\n * where it was. RedirectBoundary sends it.\n */\n notFound: 'X-RSC-Not-Found',\n\n /** Identifies the build, so a client can notice it is talking to an old one. */\n version: 'X-RSC-Version',\n\n /** The slot an intercepted navigation is targeting. */\n intercept: 'X-RSC-Intercept',\n\n /** Where the navigation or action came from. */\n referer: 'X-RSC-Referer',\n\n /** One named region of the current page to render and return alone. */\n revalidate: 'X-RSC-Revalidate',\n\n /** The server reference being invoked. */\n action: 'X-RSC-Action',\n\n /**\n * Go here instead.\n *\n * Used for a redirect the client has to perform itself: a failed action, and\n * a navigation whose render redirected. Never a 3xx for those — `fetch`\n * follows one transparently, so the client would get the destination's HTML\n * where it expected a Flight payload and decode it as one.\n */\n redirect: 'X-RSC-Redirect',\n\n /**\n * The body's real type.\n *\n * The body itself goes out as application/octet-stream so a host that parses\n * multipart cannot consume it before the action does — reading Content-Type\n * instead leaves an upload undecodable.\n */\n contentType: 'X-RSC-Content-Type',\n\n /**\n * Where the browser posts server actions.\n *\n * Not a convention this can choose: the client runtime posts here\n * unconditionally.\n */\n actionPath: '/_rsc/action',\n /**\n * Where the browser reads queries.\n *\n * A GET, and that is the whole point of it being a separate address: a POST\n * is cacheable by nothing, so a read routed through the action endpoint can\n * never be kept by an HTTP cache, a CDN or a service worker. Only functions\n * declared with `query()` are reachable here — the endpoint checks the mark\n * before invoking anything, because otherwise this address would run any\n * registered action over GET.\n */\n /**\n * Sent on every read, and required by the query endpoint.\n *\n * A GET with no unusual header is a simple request, so any page could\n * trigger one with an <img> and the visitor's cookies would ride along.\n * This header is not CORS-safelisted, so the browser preflights it — the\n * same thing that makes a POST carrying X-RSC-Action safe.\n */\n query: 'X-RSC-Query',\n\n queryPath: '/_rsc/query',\n /**\n * On a refresh a change triggered: which names moved, to which versions\n * (`stock@5,orders@2`). A shared section renders once per such change, and\n * every tab asking with the same one gets that render.\n */\n changedBy: 'X-RSC-Changed',\n /** The stream a tab hears on when a name its page refreshes on has changed. */\n changesPath: '/_rsc/changes',\n /** Whether this renderer can serve: up, and its backend answering. GET only, never cached. */\n healthPath: '/_rsc/health',\n} as const\n\n/** Flight payload. */\nexport const FLIGHT_TYPE = 'text/x-component; charset=utf-8'\n\n/** A rendered document. */\nexport const HTML_TYPE = 'text/html; charset=utf-8'\n\n/**\n * Every request header that changes what a response body contains.\n *\n * One url answers with a whole document, a partial payload, a named region or\n * an interceptor depending on these — so a cache keyed on the url alone, or on\n * `X-RSC` alone, will hand one client another's answer. They are materially\n * different bodies, not variations in presentation.\n */\nexport const VARY_ON_RSC = [\n HEADER.rsc,\n HEADER.segments,\n HEADER.revalidate,\n HEADER.intercept,\n HEADER.referer,\n].join(', ')\n\n/**\n * What a response says about being stored, when it must not be.\n *\n * `Vary` alone is not enough on the platform this targets. Cloudflare ignores\n * `Vary` for everything except `Accept-Encoding`, and this package ships a\n * Workers story as a headline feature — so one url answering with a document,\n * a Flight payload, a segment and an interceptor, keyed only on the url, hands\n * one visitor another's body. Anything narrowed by a request header, and\n * anything behind a guard, says outright that it is not to be stored.\n */\nexport const PER_CLIENT = 'private, no-store'\n\n/**\n * And what a frozen, unguarded page says.\n *\n * Explicit rather than absent: with no directive at all, whether an\n * intermediary stores it comes down to that intermediary's heuristics, which\n * is not a decision this package should be leaving to chance in either\n * direction.\n */\nexport const REVALIDATE = 'public, max-age=0, must-revalidate'\n\n/**\n * And what a page rendered for one request says.\n *\n * It may have read the visitor's cookies, and nothing in the headers - which\n * leave before the render has finished - can know whether it did. So a shared\n * cache may not keep it; the visitor's own browser may, and must ask again.\n */\nexport const PER_REQUEST = 'private, max-age=0, must-revalidate'\n\n/**\n * The edge contract: one marker, one page endpoint, one resume, for any edge\n * and any framework that implements it. Vendor-neutral names on purpose: an\n * edge speaks the contract, and there is no second way in that is rsc-kit's\n * own. docs/reference/edge-contract.mdx is the specification.\n */\nexport const EDGE = {\n prefix: '/_edge/',\n pagePath: '/_edge/page',\n resumePath: '/_edge/resume',\n tokenEnv: 'EDGE_TOKEN',\n token: 'Edge-Token',\n build: 'Edge-Build',\n /**\n * On a page request, `nonce` says the edge mints a nonce per response: a\n * shell under a Content-Security-Policy is then answered, its policy naming\n * `nonce` (the placeholder below) where the edge puts its own.\n */\n accept: 'Edge-Accept',\n /** On a resume, the nonce the edge put in the policy, for the holes' scripts. */\n nonce: 'Edge-Nonce',\n /** What the edge replaces, in every header value of the page, with its nonce. */\n noncePlaceholder: '{edge-nonce}',\n /** The marker's copy beside the stored pages, which the host reads. */\n storedMarker: '_edge.json',\n} as const\n\n/**\n * The response headers an edge may send with a page it serves from its cache\n * (the contract's `headers`), and so the only ones rscKit({ headers }) sets:\n * one outside this list could not leave with a cached page, and the page would\n * go out without it.\n */\nexport const EDGE_HEADERS = [\n 'Content-Language',\n 'Link',\n 'Cache-Control',\n 'X-Robots-Tag',\n 'Content-Security-Policy',\n 'Content-Security-Policy-Report-Only',\n 'Permissions-Policy',\n 'Referrer-Policy',\n 'Strict-Transport-Security',\n 'X-Frame-Options',\n 'X-Content-Type-Options',\n 'Cross-Origin-Opener-Policy',\n 'Cross-Origin-Embedder-Policy',\n 'Cross-Origin-Resource-Policy',\n 'X-DNS-Prefetch-Control',\n] as const\n"]}
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,sEAAsE;AACtE,wEAAwE;AACxE,2EAA2E;AAC3E,gCAAgC;AAChC,EAAE;AACF,gFAAgF;AAEhF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB;;;OAGG;IACH,GAAG,EAAE,OAAO;IAEZ,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CAAoC,CAAA;AAE9D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,qCAAqC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,MAAM,EAAE,SAAS;IACjB,QAAQ,EAAE,aAAa;IACvB,UAAU,EAAE,eAAe;IAC3B,QAAQ,EAAE,YAAY;IACtB,KAAK,EAAE,YAAY;IACnB,KAAK,EAAE,YAAY;IACnB;;;;OAIG;IACH,MAAM,EAAE,aAAa;IACrB,iFAAiF;IACjF,KAAK,EAAE,YAAY;IACnB,iFAAiF;IACjF,gBAAgB,EAAE,cAAc;IAChC,uEAAuE;IACvE,YAAY,EAAE,YAAY;CAClB,CAAA;AAEV;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,kBAAkB;IAClB,MAAM;IACN,eAAe;IACf,cAAc;IACd,yBAAyB;IACzB,qCAAqC;IACrC,oBAAoB;IACpB,iBAAiB;IACjB,2BAA2B;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,4BAA4B;IAC5B,8BAA8B;IAC9B,8BAA8B;IAC9B,wBAAwB;CAChB,CAAA","sourcesContent":["// The wire protocol, as names rather than string literals.\n//\n// A host writing these out by hand is how they drift. Two of them are not\n// negotiable at all — the client sends them or asks for them at fixed\n// addresses, and a host that spells one differently fails silently: the\n// request falls through, the decoder never runs, and a button does nothing\n// with no error on either side.\n//\n// PROTOCOL.md describes what each one means. This is the same list, importable.\n\nexport const HEADER = {\n /**\n * Present on a request for a Flight payload rather than the document. One\n * url serves both, which is why every answer must Vary on it.\n */\n rsc: 'X-RSC',\n\n /** The layout chain the client has mounted, outermost first, comma-separated. */\n segments: 'X-RSC-Segments',\n\n /** The boundary the answer replaces. 0 means a whole document. */\n segmentDepth: 'X-RSC-Segment-Depth',\n\n /** The chain to send back next time. */\n layouts: 'X-RSC-Layouts',\n\n /**\n * On a payload request: this url's page said it does not exist, after the\n * shell went out, and the client is asking for the not-found page to put\n * where it was. RedirectBoundary sends it.\n */\n notFound: 'X-RSC-Not-Found',\n\n /** Identifies the build, so a client can notice it is talking to an old one. */\n version: 'X-RSC-Version',\n\n /** The slot an intercepted navigation is targeting. */\n intercept: 'X-RSC-Intercept',\n\n /** Where the navigation or action came from. */\n referer: 'X-RSC-Referer',\n\n /** One named region of the current page to render and return alone. */\n revalidate: 'X-RSC-Revalidate',\n\n /** The server reference being invoked. */\n action: 'X-RSC-Action',\n\n /**\n * Go here instead.\n *\n * Used for a redirect the client has to perform itself: a failed action, and\n * a navigation whose render redirected. Never a 3xx for those — `fetch`\n * follows one transparently, so the client would get the destination's HTML\n * where it expected a Flight payload and decode it as one.\n */\n redirect: 'X-RSC-Redirect',\n\n /**\n * The body's real type.\n *\n * The body itself goes out as application/octet-stream so a host that parses\n * multipart cannot consume it before the action does — reading Content-Type\n * instead leaves an upload undecodable.\n */\n contentType: 'X-RSC-Content-Type',\n\n /** What every address below begins with: this package's own, on any host, whatever routes the app has. */\n endpoints: '/_rsc/',\n\n /**\n * Where the browser posts server actions.\n *\n * Not a convention this can choose: the client runtime posts here\n * unconditionally.\n */\n actionPath: '/_rsc/action',\n /**\n * Where the browser reads queries.\n *\n * A GET, and that is the whole point of it being a separate address: a POST\n * is cacheable by nothing, so a read routed through the action endpoint can\n * never be kept by an HTTP cache, a CDN or a service worker. Only functions\n * declared with `query()` are reachable here — the endpoint checks the mark\n * before invoking anything, because otherwise this address would run any\n * registered action over GET.\n */\n /**\n * Sent on every read, and required by the query endpoint.\n *\n * A GET with no unusual header is a simple request, so any page could\n * trigger one with an <img> and the visitor's cookies would ride along.\n * This header is not CORS-safelisted, so the browser preflights it — the\n * same thing that makes a POST carrying X-RSC-Action safe.\n */\n query: 'X-RSC-Query',\n\n queryPath: '/_rsc/query',\n /**\n * On a refresh a change triggered: which names moved, to which versions\n * (`stock@5,orders@2`). A shared section renders once per such change, and\n * every tab asking with the same one gets that render.\n */\n changedBy: 'X-RSC-Changed',\n /** The stream a tab hears on when a name its page refreshes on has changed. */\n changesPath: '/_rsc/changes',\n /** Whether this renderer can serve: up, and its backend answering. GET only, never cached. */\n healthPath: '/_rsc/health',\n} as const\n\n/** Flight payload. */\nexport const FLIGHT_TYPE = 'text/x-component; charset=utf-8'\n\n/** A rendered document. */\nexport const HTML_TYPE = 'text/html; charset=utf-8'\n\n/**\n * Every request header that changes what a response body contains.\n *\n * One url answers with a whole document, a partial payload, a named region or\n * an interceptor depending on these — so a cache keyed on the url alone, or on\n * `X-RSC` alone, will hand one client another's answer. They are materially\n * different bodies, not variations in presentation.\n */\nexport const VARY_ON_RSC = [\n HEADER.rsc,\n HEADER.segments,\n HEADER.revalidate,\n HEADER.intercept,\n HEADER.referer,\n].join(', ')\n\n/**\n * What a response says about being stored, when it must not be.\n *\n * `Vary` alone is not enough on the platform this targets. Cloudflare ignores\n * `Vary` for everything except `Accept-Encoding`, and this package ships a\n * Workers story as a headline feature — so one url answering with a document,\n * a Flight payload, a segment and an interceptor, keyed only on the url, hands\n * one visitor another's body. Anything narrowed by a request header, and\n * anything behind a guard, says outright that it is not to be stored.\n */\nexport const PER_CLIENT = 'private, no-store'\n\n/**\n * And what a frozen, unguarded page says.\n *\n * Explicit rather than absent: with no directive at all, whether an\n * intermediary stores it comes down to that intermediary's heuristics, which\n * is not a decision this package should be leaving to chance in either\n * direction.\n */\nexport const REVALIDATE = 'public, max-age=0, must-revalidate'\n\n/**\n * And what a page rendered for one request says.\n *\n * It may have read the visitor's cookies, and nothing in the headers - which\n * leave before the render has finished - can know whether it did. So a shared\n * cache may not keep it; the visitor's own browser may, and must ask again.\n */\nexport const PER_REQUEST = 'private, max-age=0, must-revalidate'\n\n/**\n * The edge contract: one marker, one page endpoint, one resume, for any edge\n * and any framework that implements it. Vendor-neutral names on purpose: an\n * edge speaks the contract, and there is no second way in that is rsc-kit's\n * own. docs/reference/edge-contract.mdx is the specification.\n */\nexport const EDGE = {\n prefix: '/_edge/',\n pagePath: '/_edge/page',\n resumePath: '/_edge/resume',\n tokenEnv: 'EDGE_TOKEN',\n token: 'Edge-Token',\n build: 'Edge-Build',\n /**\n * On a page request, `nonce` says the edge mints a nonce per response: a\n * shell under a Content-Security-Policy is then answered, its policy naming\n * `nonce` (the placeholder below) where the edge puts its own.\n */\n accept: 'Edge-Accept',\n /** On a resume, the nonce the edge put in the policy, for the holes' scripts. */\n nonce: 'Edge-Nonce',\n /** What the edge replaces, in every header value of the page, with its nonce. */\n noncePlaceholder: '{edge-nonce}',\n /** The marker's copy beside the stored pages, which the host reads. */\n storedMarker: '_edge.json',\n} as const\n\n/**\n * The response headers an edge may send with a page it serves from its cache\n * (the contract's `headers`), and so the only ones rscKit({ headers }) sets:\n * one outside this list could not leave with a cached page, and the page would\n * go out without it.\n */\nexport const EDGE_HEADERS = [\n 'Content-Language',\n 'Link',\n 'Cache-Control',\n 'X-Robots-Tag',\n 'Content-Security-Policy',\n 'Content-Security-Policy-Report-Only',\n 'Permissions-Policy',\n 'Referrer-Policy',\n 'Strict-Transport-Security',\n 'X-Frame-Options',\n 'X-Content-Type-Options',\n 'Cross-Origin-Opener-Policy',\n 'Cross-Origin-Embedder-Policy',\n 'Cross-Origin-Resource-Policy',\n 'X-DNS-Prefetch-Control',\n] as const\n"]}
|
package/dist/host.js
CHANGED
|
@@ -395,24 +395,6 @@ async function readBodyUpTo(request, limit) {
|
|
|
395
395
|
}
|
|
396
396
|
return body;
|
|
397
397
|
}
|
|
398
|
-
/**
|
|
399
|
-
* The page a client says it was on, as a path this router can match - or
|
|
400
|
-
* null. A header is a string anyone can send, and `new URL` throws on one
|
|
401
|
-
* that is not a url; that must not become a 500 on the action endpoint.
|
|
402
|
-
*/
|
|
403
|
-
function refererPath(referer, origin, hosts = []) {
|
|
404
|
-
if (!referer)
|
|
405
|
-
return null;
|
|
406
|
-
try {
|
|
407
|
-
const parsed = new URL(referer, origin);
|
|
408
|
-
// The page the action was invoked from is routed the way a request for
|
|
409
|
-
// it would be: on a tenant host, the referer's host names the segment.
|
|
410
|
-
return hostPath(parsed.host, parsed.pathname, hosts);
|
|
411
|
-
}
|
|
412
|
-
catch {
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
398
|
/**
|
|
417
399
|
* The url of the page an action was invoked from, query string included -
|
|
418
400
|
* or undefined. On this origin whatever the header names: it only ever
|
|
@@ -956,6 +938,41 @@ export function createRscHandler(options) {
|
|
|
956
938
|
headers.set("location", placed);
|
|
957
939
|
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
958
940
|
}
|
|
941
|
+
/** The host the visitor asked for. Behind a proxy the url names this process instead. */
|
|
942
|
+
function requestHost(request, url) {
|
|
943
|
+
return request.headers.get("x-forwarded-host") ?? request.headers.get("host") ?? url.host;
|
|
944
|
+
}
|
|
945
|
+
/** The url the router matches for this path on this host: the host's segment in front, when a route begins with it. */
|
|
946
|
+
function onHost(url, host) {
|
|
947
|
+
const segment = hostSegment(host, siteHosts);
|
|
948
|
+
if (segment === null || !routableHost(segment, routes.routes))
|
|
949
|
+
return url;
|
|
950
|
+
const routed = new URL(hostPath(host, url.pathname, siteHosts) + url.search, url.origin);
|
|
951
|
+
hostOf.set(routed, segment);
|
|
952
|
+
return routed;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* The page a client says it was on, as a url this router can match - or
|
|
956
|
+
* null. A header is a string anyone can send, and `new URL` throws on one
|
|
957
|
+
* that is not a url; that must not become a 500 on the action endpoint.
|
|
958
|
+
*
|
|
959
|
+
* The client sends a path, so its host is the request's: behind a proxy the
|
|
960
|
+
* url names this process, and /login from merchant.example.com was looked
|
|
961
|
+
* up as the site's own /login.
|
|
962
|
+
*/
|
|
963
|
+
function refererUrl(request, url) {
|
|
964
|
+
const referer = request.headers.get(HEADER.referer);
|
|
965
|
+
if (!referer)
|
|
966
|
+
return null;
|
|
967
|
+
try {
|
|
968
|
+
const parsed = new URL(referer, url.origin);
|
|
969
|
+
const host = parsed.origin === url.origin ? requestHost(request, url) : parsed.host;
|
|
970
|
+
return onHost(new URL(parsed.pathname, url.origin), host);
|
|
971
|
+
}
|
|
972
|
+
catch {
|
|
973
|
+
return null;
|
|
974
|
+
}
|
|
975
|
+
}
|
|
959
976
|
async function routeOnHost(request) {
|
|
960
977
|
let url = new URL(request.url);
|
|
961
978
|
// rscKit({ subdomains }): a page under one of those directories has one
|
|
@@ -987,14 +1004,15 @@ export function createRscHandler(options) {
|
|
|
987
1004
|
// one named for the host - so an app with a metadataBase and no tenant
|
|
988
1005
|
// tree routes every host by path, and a proxy forwarding by an internal
|
|
989
1006
|
// name is not read as a tenant.
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1007
|
+
//
|
|
1008
|
+
// Never this package's own endpoints. The browser posts to /_rsc/action
|
|
1009
|
+
// whatever host its page is on, and with the segment in front it is
|
|
1010
|
+
// /merchant/_rsc/action: no route, and a 404 for every action there.
|
|
1011
|
+
if (siteHosts.length > 0 && !url.pathname.startsWith(HEADER.endpoints)) {
|
|
1012
|
+
const host = requestHost(request, url);
|
|
994
1013
|
const segment = hostSegment(host, siteHosts);
|
|
995
1014
|
if (segment !== null && routableHost(segment, routes.routes)) {
|
|
996
|
-
url =
|
|
997
|
-
hostOf.set(url, segment);
|
|
1015
|
+
url = onHost(url, host);
|
|
998
1016
|
}
|
|
999
1017
|
else if (segment !== null && host && siteHosts.some((site) => bareHost(host).endsWith("." + site))) {
|
|
1000
1018
|
// A label under the site's own host, not a foreign one: a foreign
|
|
@@ -2114,8 +2132,8 @@ export function createRscHandler(options) {
|
|
|
2114
2132
|
return new Response("Not found", { status: 404 });
|
|
2115
2133
|
if (refusal)
|
|
2116
2134
|
return refusal;
|
|
2117
|
-
const from =
|
|
2118
|
-
const under = from ?
|
|
2135
|
+
const from = refererUrl(request, url);
|
|
2136
|
+
const under = from ? matchPage(routes, from) : null;
|
|
2119
2137
|
// Without a page to open over there is nothing to intercept: render the
|
|
2120
2138
|
// interceptor on its own rather than answering with the wrong page.
|
|
2121
2139
|
const component = under ? under.route.component : intercept.component;
|
|
@@ -2299,10 +2317,10 @@ export function createRscHandler(options) {
|
|
|
2299
2317
|
const contentType = request.headers.get(HEADER.contentType) ?? "text/plain;charset=UTF-8";
|
|
2300
2318
|
// Where it was invoked from, so anything the action invalidates can be
|
|
2301
2319
|
// re-rendered against the page that is actually on screen.
|
|
2302
|
-
const from =
|
|
2303
|
-
const match = from ?
|
|
2320
|
+
const from = refererUrl(request, url);
|
|
2321
|
+
const match = from ? matchPage(routes, from) : null;
|
|
2304
2322
|
const page = match
|
|
2305
|
-
? pageContext(match, await propsFor(match, request), from
|
|
2323
|
+
? pageContext(match, await propsFor(match, request), from?.pathname, pageHref(request.headers.get(HEADER.referer), url.origin))
|
|
2306
2324
|
: undefined;
|
|
2307
2325
|
// Scoped to this action: revalidate() called anywhere inside it, at any
|
|
2308
2326
|
// depth, marks here and nowhere else — two requests can be in flight and
|