Skip to content

Commit 5811aea

Browse files
Pass trailingSlash from Next.js config to firebase.json (#5445)
* Don't use internal redirects for the backend test * pass trailingSlash from next config to firebase.json Co-authored-by: James Daniels <[email protected]>
1 parent d59b78b commit 5811aea

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
- Refactors Functions Emulator. (#5422)
22
- Fixes race condition when discovering functions. (#5444)
33
- Fixes issue where `init firestore` was unecessarilly checking for default resource location. (#5230 and #5452)
4+
- Pass `trailingSlash` from Next.js config to `firebase.json` (#5445)
5+
- Don't use Next.js internal redirects for the backend test (#5445)

src/frameworks/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface BuildResult {
4141
redirects?: any[];
4242
headers?: any[];
4343
wantsBackend?: boolean;
44+
trailingSlash?: boolean;
4445
}
4546

4647
export interface Framework {
@@ -405,10 +406,12 @@ export async function prepareFrameworks(
405406
rewrites = [],
406407
redirects = [],
407408
headers = [],
409+
trailingSlash,
408410
} = (await build(getProjectPath())) || {};
409411
config.rewrites.push(...rewrites);
410412
config.redirects.push(...redirects);
411413
config.headers.push(...headers);
414+
config.trailingSlash ??= trailingSlash;
412415
if (await pathExists(hostingDist)) await rm(hostingDist, { recursive: true });
413416
await mkdirp(hostingDist);
414417
await ɵcodegenPublicDirectory(getProjectPath(), hostingDist);

src/frameworks/next/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export async function build(dir: string): Promise<BuildResult> {
9595
});
9696

9797
const reasonsForBackend = [];
98-
const { distDir } = await getConfig(dir);
98+
const { distDir, trailingSlash } = await getConfig(dir);
9999

100100
if (await isUsingMiddleware(join(dir, distDir), false)) {
101101
reasonsForBackend.push("middleware");
@@ -171,7 +171,9 @@ export async function build(dir: string): Promise<BuildResult> {
171171
headers,
172172
}));
173173

174-
const isEveryRedirectSupported = nextJsRedirects.every(isRedirectSupportedByHosting);
174+
const isEveryRedirectSupported = nextJsRedirects
175+
.filter((it) => !it.internal)
176+
.every(isRedirectSupportedByHosting);
175177
if (!isEveryRedirectSupported) {
176178
reasonsForBackend.push("advanced redirects");
177179
}
@@ -227,7 +229,7 @@ export async function build(dir: string): Promise<BuildResult> {
227229
console.log("");
228230
}
229231

230-
return { wantsBackend, headers, redirects, rewrites };
232+
return { wantsBackend, headers, redirects, rewrites, trailingSlash };
231233
}
232234

233235
/**
@@ -442,5 +444,10 @@ async function getConfig(dir: string): Promise<NextConfig & { distDir: string }>
442444
}
443445
}
444446
}
445-
return { distDir: ".next", ...config };
447+
return {
448+
distDir: ".next",
449+
// trailingSlash defaults to false in Next.js: https://nextjs.org/docs/api-reference/next.config.js/trailing-slash
450+
trailingSlash: false,
451+
...config,
452+
};
446453
}

0 commit comments

Comments
 (0)