File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,6 @@ import { NextRequest, NextResponse } from "next/server"
2
2
3
3
import { DEFAULT_LOCALE , FAKE_LOCALE , LOCALES_CODES } from "./lib/constants"
4
4
5
- const PUBLIC_FILE = / \. ( .* ) $ /
6
-
7
5
function detectLocale ( acceptLanguage : string | null ) {
8
6
if ( ! acceptLanguage ) {
9
7
return DEFAULT_LOCALE
@@ -21,17 +19,23 @@ function detectLocale(acceptLanguage: string | null) {
21
19
return locale
22
20
}
23
21
22
+ export const config = {
23
+ matcher : [
24
+ /*
25
+ * Match all request paths except for the ones starting with:
26
+ * - api (API routes)
27
+ * - _next/static (static files)
28
+ * - _next/image (image optimization files)
29
+ * - favicon.ico (favicon file)
30
+ * - .well-known (security files)
31
+ */
32
+ "/((?!api|_next/static|_next/image|favicon.ico|.well-known).*)" ,
33
+ ] ,
34
+ }
35
+
24
36
// Middleware required to always display the locale prefix in the URL. It
25
37
// redirects to the default locale if the locale is not present in the URL
26
38
export async function middleware ( req : NextRequest ) {
27
- if (
28
- req . nextUrl . pathname . startsWith ( "/_next" ) ||
29
- req . nextUrl . pathname . includes ( "/api/" ) ||
30
- PUBLIC_FILE . test ( req . nextUrl . pathname )
31
- ) {
32
- return
33
- }
34
-
35
39
if ( req . nextUrl . locale === FAKE_LOCALE ) {
36
40
// Apparently, the built-in `localeDetection`from Next does not work when
37
41
// using the faked locale hack. So, we need to detect the locale manually
You can’t perform that action at this time.
0 commit comments