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

Bump netlify/next runtime and fix api routes in middleware #13040

Merged
merged 5 commits into from
Jun 12, 2024
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
24 changes: 1 addition & 23 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,4 @@
[[plugins.inputs.audits]]
path = "en/developers/docs/intro-to-ethereum/"
[[plugins.inputs.audits]]
path = "en/developers/tutorials/creating-a-wagmi-ui-for-your-contract/"

[functions]

[functions.___netlify-odb-handler]
external_node_modules = ["sharp"]
included_files = [
"./src/intl/**/*",
"!./public/**/*",
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/router-context*",
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/amp-context*",
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context*",
"node_modules/sharp/**/*",
]

[functions.___netlify-handler]
included_files = [
"./src/intl/**/*",
"!./public/**/*",
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/router-context*",
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/amp-context*",
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context*",
]
path = "en/developers/tutorials/creating-a-wagmi-ui-for-your-contract/"
24 changes: 23 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,29 @@ module.exports = (phase, { defaultConfig }) => {
}

if (phase !== PHASE_DEVELOPMENT_SERVER) {
nextConfig = { ...nextConfig, experimental }
nextConfig = {
...nextConfig,
experimental: {
...experimental,
outputFileTracingExcludes: {
"*": [
/**
* Exclude these paths from the trace output to avoid bloating the
* Netlify functions bundle.
*
* @see https://github.com/orgs/vercel/discussions/103#discussioncomment-5427097
* @see https://nextjs.org/docs/app/api-reference/next-config-js/output#automatically-copying-traced-files
*/
"node_modules/@swc/core-linux-x64-gnu",
"node_modules/@swc/core-linux-x64-musl",
"node_modules/@esbuild/linux-x64",
"public/**/*.png",
"public/**/*.gif",
"src/data",
],
},
},
}
}

return nextConfig
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"devDependencies": {
"@chakra-ui/cli": "^2.4.1",
"@netlify/plugin-nextjs": "^4.41.3",
"@netlify/plugin-nextjs": "^5.0.0",
"@storybook/addon-essentials": "7.6.6",
"@storybook/addon-interactions": "7.6.6",
"@storybook/addon-links": "7.6.6",
Expand Down
19 changes: 10 additions & 9 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ export const config = {
"/", // explicit matcher for root route
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
*/
"/((?!api|_next/static).*)",
"/((?!_next/static).*)",
],
}

// Middleware required to always display the locale prefix in the URL. It
// redirects to the default locale if the locale is not present in the URL
export async function middleware(req: NextRequest) {
const { pathname, locale } = req.nextUrl

if (pathname.startsWith("/_next") || PUBLIC_FILE.test(pathname)) {
return NextResponse.next()
const { pathname, locale, search } = req.nextUrl

if (
pathname.startsWith("/_next") ||
pathname.includes("/api/") ||
PUBLIC_FILE.test(pathname)
) {
return
}

if (locale === FAKE_LOCALE) {
Expand All @@ -48,7 +51,7 @@ export async function middleware(req: NextRequest) {
const localeDetected = detectLocale(req.headers.get("accept-language"))
const locale = localeDetected || DEFAULT_LOCALE

const redirectUrl = new URL(`/${locale}${pathname}`, req.url)
const redirectUrl = new URL(`/${locale}${pathname}${search}`, req.url)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the search params to the redirect, thing that was missing.


// Add trailing slash if it's not present
if (!redirectUrl.pathname.endsWith("/")) {
Expand All @@ -57,6 +60,4 @@ export async function middleware(req: NextRequest) {

return NextResponse.redirect(redirectUrl, { status: 301 })
}

return NextResponse.next()
}
Loading
Loading