updated docs
This commit is contained in:
@@ -91,20 +91,21 @@ export const i18nConfig = {
|
||||
} as const // as const — inaczej TS: locales nie pasuje do niepustej tuple
|
||||
```
|
||||
|
||||
Importuj w: payload.config (ipalKit({ i18n: i18nConfig })), middleware.ts.
|
||||
Importuj w: payload.config (ipalKit({ i18n: i18nConfig })), proxy.ts.
|
||||
Layout może czytać locale z payload config (config.localization.locales) —
|
||||
też jedno źródło.
|
||||
|
||||
## Middleware
|
||||
## Proxy (dawniej middleware)
|
||||
|
||||
> **Next 16:** konwencja `middleware.ts` jest deprecated na rzecz `proxy.ts`
|
||||
> (plik `proxy.ts`, funkcja `export function proxy`). Logika pluginu bez zmian —
|
||||
> `createLocaleMiddleware` działa tak samo, zmienia się tylko nazwa pliku i
|
||||
> funkcji po stronie projektu. Na razie `middleware.ts` działa z ostrzeżeniem.
|
||||
> funkcji po stronie projektu. Migracja jedną komendą:
|
||||
> `npx @next/codemod@canary middleware-to-proxy .`
|
||||
|
||||
|
||||
```ts
|
||||
// src/middleware.ts
|
||||
// src/proxy.ts
|
||||
import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
import { createLocaleMiddleware } from '@intecion/ipal-kit/next/middleware'
|
||||
@@ -112,16 +113,17 @@ import { i18nConfig } from '@/i18n.config'
|
||||
|
||||
const localeMiddleware = createLocaleMiddleware({ config: i18nConfig })
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
export function proxy(request: NextRequest) {
|
||||
const result = localeMiddleware(request)
|
||||
if (result.type === 'next') return NextResponse.next()
|
||||
const response = NextResponse.redirect(result.location)
|
||||
response.cookies.set(result.cookie.name, result.cookie.value)
|
||||
// cookie tylko gdy jest zgoda na kategorię functional — inaczej undefined
|
||||
if (result.cookie) response.cookies.set(result.cookie.name, result.cookie.value)
|
||||
return response
|
||||
}
|
||||
|
||||
// matcher MUSI być inline (Next analizuje statycznie, nie wykonuje importów —
|
||||
// import DEFAULT_MIDDLEWARE_MATCHER byłby zignorowany → middleware łapie
|
||||
// import DEFAULT_MIDDLEWARE_MATCHER byłby zignorowany → proxy łapie
|
||||
// /admin /_next /api → 500)
|
||||
export const config = {
|
||||
matcher: ['/((?!api|admin|_next|.*\\..*).*)'],
|
||||
|
||||
Reference in New Issue
Block a user