Skip to content

Commit

Permalink
Pass trailingSlash from Next.js config to firebase.json (#5445)
Browse files Browse the repository at this point in the history
* Don't use internal redirects for the backend test
* pass trailingSlash from next config to firebase.json

Co-authored-by: James Daniels <jamesdaniels@google.com>
  • Loading branch information
leoortizz and jamesdaniels committed Jan 26, 2023
1 parent d59b78b commit 5811aea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Refactors Functions Emulator. (#5422)
- Fixes race condition when discovering functions. (#5444)
- Fixes issue where `init firestore` was unecessarilly checking for default resource location. (#5230 and #5452)
- Pass `trailingSlash` from Next.js config to `firebase.json` (#5445)
- Don't use Next.js internal redirects for the backend test (#5445)
3 changes: 3 additions & 0 deletions src/frameworks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface BuildResult {
redirects?: any[];
headers?: any[];
wantsBackend?: boolean;
trailingSlash?: boolean;
}

export interface Framework {
Expand Down Expand Up @@ -405,10 +406,12 @@ export async function prepareFrameworks(
rewrites = [],
redirects = [],
headers = [],
trailingSlash,
} = (await build(getProjectPath())) || {};
config.rewrites.push(...rewrites);
config.redirects.push(...redirects);
config.headers.push(...headers);
config.trailingSlash ??= trailingSlash;
if (await pathExists(hostingDist)) await rm(hostingDist, { recursive: true });
await mkdirp(hostingDist);
await ɵcodegenPublicDirectory(getProjectPath(), hostingDist);
Expand Down
15 changes: 11 additions & 4 deletions src/frameworks/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function build(dir: string): Promise<BuildResult> {
});

const reasonsForBackend = [];
const { distDir } = await getConfig(dir);
const { distDir, trailingSlash } = await getConfig(dir);

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

const isEveryRedirectSupported = nextJsRedirects.every(isRedirectSupportedByHosting);
const isEveryRedirectSupported = nextJsRedirects
.filter((it) => !it.internal)
.every(isRedirectSupportedByHosting);
if (!isEveryRedirectSupported) {
reasonsForBackend.push("advanced redirects");
}
Expand Down Expand Up @@ -227,7 +229,7 @@ export async function build(dir: string): Promise<BuildResult> {
console.log("");
}

return { wantsBackend, headers, redirects, rewrites };
return { wantsBackend, headers, redirects, rewrites, trailingSlash };
}

/**
Expand Down Expand Up @@ -442,5 +444,10 @@ async function getConfig(dir: string): Promise<NextConfig & { distDir: string }>
}
}
}
return { distDir: ".next", ...config };
return {
distDir: ".next",
// trailingSlash defaults to false in Next.js: https://nextjs.org/docs/api-reference/next.config.js/trailing-slash
trailingSlash: false,
...config,
};
}

0 comments on commit 5811aea

Please sign in to comment.