Skip to content

Commit

Permalink
Merge pull request #13040 from ethereum/fixed-locale-prefix
Browse files Browse the repository at this point in the history
Bump netlify/next runtime and fix api routes in middleware
  • Loading branch information
wackerow authored Jun 12, 2024
2 parents 211417a + 2de39bc commit 7610f4a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 764 deletions.
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)

// 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

0 comments on commit 7610f4a

Please sign in to comment.