From 5811aea8ca0c9628cfdc3ef24ba57a9eb363e8b5 Mon Sep 17 00:00:00 2001 From: Leonardo Ortiz Date: Thu, 26 Jan 2023 17:30:31 -0300 Subject: [PATCH] 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 --- CHANGELOG.md | 2 ++ src/frameworks/index.ts | 3 +++ src/frameworks/next/index.ts | 15 +++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fcec825e1c3..5349e595ed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/frameworks/index.ts b/src/frameworks/index.ts index 2a6222b9b11..eec612381a4 100644 --- a/src/frameworks/index.ts +++ b/src/frameworks/index.ts @@ -41,6 +41,7 @@ export interface BuildResult { redirects?: any[]; headers?: any[]; wantsBackend?: boolean; + trailingSlash?: boolean; } export interface Framework { @@ -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); diff --git a/src/frameworks/next/index.ts b/src/frameworks/next/index.ts index 9e1b8690e37..0a4db4994ff 100644 --- a/src/frameworks/next/index.ts +++ b/src/frameworks/next/index.ts @@ -95,7 +95,7 @@ export async function build(dir: string): Promise { }); const reasonsForBackend = []; - const { distDir } = await getConfig(dir); + const { distDir, trailingSlash } = await getConfig(dir); if (await isUsingMiddleware(join(dir, distDir), false)) { reasonsForBackend.push("middleware"); @@ -171,7 +171,9 @@ export async function build(dir: string): Promise { headers, })); - const isEveryRedirectSupported = nextJsRedirects.every(isRedirectSupportedByHosting); + const isEveryRedirectSupported = nextJsRedirects + .filter((it) => !it.internal) + .every(isRedirectSupportedByHosting); if (!isEveryRedirectSupported) { reasonsForBackend.push("advanced redirects"); } @@ -227,7 +229,7 @@ export async function build(dir: string): Promise { console.log(""); } - return { wantsBackend, headers, redirects, rewrites }; + return { wantsBackend, headers, redirects, rewrites, trailingSlash }; } /** @@ -442,5 +444,10 @@ async function getConfig(dir: string): Promise } } } - 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, + }; }