1- import fs from 'node:fs/promises' ;
2- import path from 'node:path' ;
31import {
42 type MiddlewareHandler ,
53 defineServerConfig ,
@@ -24,59 +22,20 @@ const shouldProxyRemoteAsset = (pathname: string) => {
2422const REMOTE_COUNTER_ALIAS_MODULE =
2523 'remote-module:rscRemote:./src/components/RemoteClientCounter.tsx' ;
2624const REMOTE_COUNTER_SOURCE_MODULE = './src/components/RemoteClientCounter.tsx' ;
27- const REMOTE_ACTION_ID_TO_PROXY_EXPORT = {
25+ const REMOTE_ACTION_ID_TO_PROXY_ACTION_ID = {
2826 '606c30f35d74d843171a8a71358eda595991e4ee16270e9f052af3faef57a19999' :
29- 'proxyIncrementRemoteCount ' ,
27+ '603cd42bd1c9b98894c6d03b3b688f513073ddbea04bb02d7fda1e72c57f96b69d ' ,
3028 '40e41a2ee9d9de373b364dcf2a0201701057c8502037bf9ef2cd26bb2a1259dabd' :
31- 'proxyRemoteActionEcho ' ,
29+ '40f14c24f6d81be75aab6d9dc7941b9507bfbdb9daca25df7b1aed34703972c7ab ' ,
3230 '408da81ddb8214f8cb98a83552cb70c4d17b27b6fd36d972cac89e7030a4874fd4' :
33- 'proxyNestedRemoteAction ' ,
31+ '40928b48a8dc80bb3a73661fbdbeb14155a85a1b965e9ef67a8f4132bbd4dda7e5 ' ,
3432 '40fd3fd0c01e4d21630b7f6f902c1ddc49d3b05418ca1da003c4fdc6c6272e0bf2' :
35- 'proxyDefaultRemoteAction ' ,
33+ '404768f4f5d65c3edafd60e28fc1252837ade49f3b06dad341098530dea5bb7716 ' ,
3634} as const ;
3735const PROXY_REQUEST_HEADER = 'x-rsc-mf-proxy-action' ;
3836const createRemoteNestedMixedAliasChunk = ( ) =>
3937 `\n;(globalThis["chunk_rscHost"] = globalThis["chunk_rscHost"] || []).push([["__federation_expose_RemoteNestedMixed_alias"],{"${ REMOTE_COUNTER_ALIAS_MODULE } ":function(module,__unused,__webpack_require__){module.exports=__webpack_require__("${ REMOTE_COUNTER_SOURCE_MODULE } ");}}]);` ;
4038
41- let cachedProxyActionIds :
42- | Partial <
43- Record <
44- ( typeof REMOTE_ACTION_ID_TO_PROXY_EXPORT ) [ keyof typeof REMOTE_ACTION_ID_TO_PROXY_EXPORT ] ,
45- string
46- >
47- >
48- | undefined ;
49-
50- const getProxyActionIds = async ( ) => {
51- if ( cachedProxyActionIds ) {
52- return cachedProxyActionIds ;
53- }
54-
55- const serverBundlePath = path . resolve (
56- process . cwd ( ) ,
57- 'dist/bundles/server-component-root.js' ,
58- ) ;
59- const serverBundleCode = await fs . readFile ( serverBundlePath , 'utf-8' ) ;
60-
61- const actionIdMap : Partial <
62- Record <
63- ( typeof REMOTE_ACTION_ID_TO_PROXY_EXPORT ) [ keyof typeof REMOTE_ACTION_ID_TO_PROXY_EXPORT ] ,
64- string
65- >
66- > = { } ;
67- Object . values ( REMOTE_ACTION_ID_TO_PROXY_EXPORT ) . forEach ( exportName => {
68- const pattern = new RegExp (
69- `registerServerReference\\\\)\\\\(${ exportName } ,\\\\s*"([^"]+)"` ,
70- ) ;
71- const match = serverBundleCode . match ( pattern ) ;
72- if ( match ?. [ 1 ] ) {
73- actionIdMap [ exportName ] = match [ 1 ] ;
74- }
75- } ) ;
76- cachedProxyActionIds = actionIdMap ;
77- return actionIdMap ;
78- } ;
79-
8039const proxyRemoteRscAction : MiddlewareHandler = async ( c , next ) => {
8140 const request = c . req . raw ;
8241 if ( request . method !== 'POST' ) {
@@ -95,17 +54,10 @@ const proxyRemoteRscAction: MiddlewareHandler = async (c, next) => {
9554 return ;
9655 }
9756
98- const proxyExportName =
99- REMOTE_ACTION_ID_TO_PROXY_EXPORT [
100- actionId as keyof typeof REMOTE_ACTION_ID_TO_PROXY_EXPORT
57+ const proxyActionId =
58+ REMOTE_ACTION_ID_TO_PROXY_ACTION_ID [
59+ actionId as keyof typeof REMOTE_ACTION_ID_TO_PROXY_ACTION_ID
10160 ] ;
102- if ( ! proxyExportName ) {
103- await next ( ) ;
104- return ;
105- }
106-
107- const proxyActionIds = await getProxyActionIds ( ) . catch ( ( ) => undefined ) ;
108- const proxyActionId = proxyActionIds ?. [ proxyExportName ] ;
10961 if ( ! proxyActionId ) {
11062 await next ( ) ;
11163 return ;
0 commit comments