Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle 404 status code in the proxyResponse. #8119

Merged
merged 6 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes issue with custom 404 pages not being returned in Next.js in the emulator (#8035).
7 changes: 6 additions & 1 deletion src/frameworks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

// Use "true &&"" to keep typescript from compiling this file and rewriting
// the import statement into a require
const { dynamicImport } = require(true && "../dynamicImport");

Check warning on line 26 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 26 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

const NPM_ROOT_TIMEOUT_MILLIES = 5_000;
const NPM_ROOT_MEMO = new Map<string, string>();
Expand All @@ -40,7 +40,7 @@
*
* Note: `throws: false` won't work with the async function: https://github.com/jprichardson/node-fs-extra/issues/542
*/
export function readJSON<JsonType = any>(

Check warning on line 43 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
file: string,
options?: ReadOptions | BufferEncoding | string,
): Promise<JsonType> {
Expand All @@ -57,10 +57,10 @@
defaultBuildScripts: string[],
): Promise<void> {
const packageJsonBuffer = await readFile(join(dir, "package.json"));
const packageJson = JSON.parse(packageJsonBuffer.toString());

Check warning on line 60 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const buildScript = packageJson.scripts?.build;

Check warning on line 61 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 61 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .scripts on an `any` value

if (buildScript && !defaultBuildScripts.includes(buildScript)) {

Check warning on line 63 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe argument of type `any` assigned to a parameter of type `string`
console.warn(
`\nWARNING: Your package.json contains a custom build that is being ignored. Only the ${framework} default build script (e.g, "${defaultBuildScripts[0]}") is respected. If you have a more advanced build process you should build a custom integration https://firebase.google.com/docs/hosting/express\n`,
);
Expand Down Expand Up @@ -149,7 +149,7 @@
next();
} else {
for (const [fn, args] of buffer) {
(res as any)[fn](...args);

Check warning on line 152 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access [fn] on an `any` value

Check warning on line 152 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 152 in src/frameworks/utils.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
}
res.end(...args);
buffer.length = 0;
Expand Down Expand Up @@ -208,7 +208,12 @@
originalRes.end();
});
} else {
const proxiedRes = proxyResponse(originalReq, originalRes, next);
const proxiedRes = proxyResponse(originalReq, originalRes, () => {
// This next function is called when the proxied response is a 404
// In that case we want to let the handler to use the original response
void hostOrRequestHandler(originalReq, originalRes, next);
});

await hostOrRequestHandler(originalReq, proxiedRes, next);
}
};
Expand Down
Loading