Skip to content

Commit 7fc15bf

Browse files
committed
fix(rsc-mf): skip host proxy on internal fallback requests
1 parent 80084f9 commit 7fc15bf

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

tests/integration/rsc-mf/host/server/modern.server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ const shouldProxyRemoteAsset = (pathname: string) => {
100100
};
101101

102102
const proxyRemoteFederationAsset: MiddlewareHandler = async (c, next) => {
103+
const requestHeaders = c.req.headers;
104+
const isInternalFallbackFetch =
105+
requestHeaders?.get?.(INTERNAL_FALLBACK_HEADER) === '1';
106+
if (isInternalFallbackFetch) {
107+
await next();
108+
return;
109+
}
110+
103111
const reqUrl = new URL(c.req.url);
104112
const pathname = reqUrl.pathname;
105113

tests/integration/rsc-mf/tests/modernServerConfig.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ const getProxyMiddlewareHandler = () => {
6262
expect(middleware.before).toEqual(['server-static']);
6363
expect(typeof middleware.handler).toBe('function');
6464
return middleware.handler as (
65-
c: { req: { url: string }; res?: Response },
65+
c: {
66+
req: { url: string; headers?: { get?: (name: string) => string | null } };
67+
res?: Response;
68+
},
6669
next: () => Promise<void>,
6770
) => Promise<void>;
6871
};
@@ -228,6 +231,32 @@ describe('rsc-mf host modern.server middleware contracts', () => {
228231
expect(context.res).toBeUndefined();
229232
});
230233

234+
it('skips proxying when request is marked as internal fallback fetch', async () => {
235+
const handler = getProxyMiddlewareHandler();
236+
const next = jest.fn(async (): Promise<void> => undefined);
237+
const fetchMock = installFetchMock(
238+
async () => new Response('ignored', { status: 200 }),
239+
);
240+
const context: {
241+
req: { url: string; headers?: { get?: (name: string) => string | null } };
242+
res?: Response;
243+
} = {
244+
req: {
245+
url: 'http://127.0.0.1:3007/static/js/async/__federation_expose_actions.44d8f1d7ae.js',
246+
headers: {
247+
get: (name: string) =>
248+
name === INTERNAL_FALLBACK_HEADER ? '1' : undefined,
249+
},
250+
},
251+
};
252+
253+
await withRemotePort('3999', () => handler(context, next));
254+
255+
expect(fetchMock).not.toHaveBeenCalled();
256+
expect(next).toHaveBeenCalledTimes(1);
257+
expect(context.res).toBeUndefined();
258+
});
259+
231260
it('falls through when remote port is not configured', async () => {
232261
const handler = getProxyMiddlewareHandler();
233262
const next = jest.fn(async (): Promise<void> => undefined);

0 commit comments

Comments
 (0)