Skip to content

Commit 7610f4a

Browse files
authored
Merge pull request #13040 from ethereum/fixed-locale-prefix
Bump netlify/next runtime and fix api routes in middleware
2 parents 211417a + 2de39bc commit 7610f4a

File tree

5 files changed

+60
-764
lines changed

5 files changed

+60
-764
lines changed

netlify.toml

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,4 @@
3636
[[plugins.inputs.audits]]
3737
path = "en/developers/docs/intro-to-ethereum/"
3838
[[plugins.inputs.audits]]
39-
path = "en/developers/tutorials/creating-a-wagmi-ui-for-your-contract/"
40-
41-
[functions]
42-
43-
[functions.___netlify-odb-handler]
44-
external_node_modules = ["sharp"]
45-
included_files = [
46-
"./src/intl/**/*",
47-
"!./public/**/*",
48-
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/router-context*",
49-
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/amp-context*",
50-
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context*",
51-
"node_modules/sharp/**/*",
52-
]
53-
54-
[functions.___netlify-handler]
55-
included_files = [
56-
"./src/intl/**/*",
57-
"!./public/**/*",
58-
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/router-context*",
59-
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/amp-context*",
60-
"node_modules/next/dist/server/future/route-modules/pages/vendored/contexts/head-manager-context*",
61-
]
39+
path = "en/developers/tutorials/creating-a-wagmi-ui-for-your-contract/"

next.config.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,29 @@ module.exports = (phase, { defaultConfig }) => {
4141
}
4242

4343
if (phase !== PHASE_DEVELOPMENT_SERVER) {
44-
nextConfig = { ...nextConfig, experimental }
44+
nextConfig = {
45+
...nextConfig,
46+
experimental: {
47+
...experimental,
48+
outputFileTracingExcludes: {
49+
"*": [
50+
/**
51+
* Exclude these paths from the trace output to avoid bloating the
52+
* Netlify functions bundle.
53+
*
54+
* @see https://github.com/orgs/vercel/discussions/103#discussioncomment-5427097
55+
* @see https://nextjs.org/docs/app/api-reference/next-config-js/output#automatically-copying-traced-files
56+
*/
57+
"node_modules/@swc/core-linux-x64-gnu",
58+
"node_modules/@swc/core-linux-x64-musl",
59+
"node_modules/@esbuild/linux-x64",
60+
"public/**/*.png",
61+
"public/**/*.gif",
62+
"src/data",
63+
],
64+
},
65+
},
66+
}
4567
}
4668

4769
return nextConfig

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
},
6262
"devDependencies": {
6363
"@chakra-ui/cli": "^2.4.1",
64-
"@netlify/plugin-nextjs": "^4.41.3",
64+
"@netlify/plugin-nextjs": "^5.0.0",
6565
"@storybook/addon-essentials": "7.6.6",
6666
"@storybook/addon-interactions": "7.6.6",
6767
"@storybook/addon-links": "7.6.6",

src/middleware.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ export const config = {
2626
"/", // explicit matcher for root route
2727
/*
2828
* Match all request paths except for the ones starting with:
29-
* - api (API routes)
3029
* - _next/static (static files)
3130
*/
32-
"/((?!api|_next/static).*)",
31+
"/((?!_next/static).*)",
3332
],
3433
}
3534

3635
// Middleware required to always display the locale prefix in the URL. It
3736
// redirects to the default locale if the locale is not present in the URL
3837
export async function middleware(req: NextRequest) {
39-
const { pathname, locale } = req.nextUrl
40-
41-
if (pathname.startsWith("/_next") || PUBLIC_FILE.test(pathname)) {
42-
return NextResponse.next()
38+
const { pathname, locale, search } = req.nextUrl
39+
40+
if (
41+
pathname.startsWith("/_next") ||
42+
pathname.includes("/api/") ||
43+
PUBLIC_FILE.test(pathname)
44+
) {
45+
return
4346
}
4447

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

51-
const redirectUrl = new URL(`/${locale}${pathname}`, req.url)
54+
const redirectUrl = new URL(`/${locale}${pathname}${search}`, req.url)
5255

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

5861
return NextResponse.redirect(redirectUrl, { status: 301 })
5962
}
60-
61-
return NextResponse.next()
6263
}

0 commit comments

Comments
 (0)