Skip to content

Commit

Permalink
feat: use local normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattjoh committed May 28, 2024
1 parent 49d8c67 commit a01691d
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import { BasePathPathnameNormalizer } from '../future/normalizers/request/base-p
import { addRequestMeta, type NextUrlWithParsedQuery } from '../request-meta'
import { format } from 'url'
import { parseUrl } from '../../shared/lib/router/utils/parse-url'
import { LocaleRouteNormalizer } from '../future/normalizers/locale-route-normalizer'

export class BaseRequestAdapter<ServerRequest extends BaseNextRequest>
implements RequestAdapter<ServerRequest>
{
protected readonly normalizers: {
readonly basePath: BasePathPathnameNormalizer | undefined
readonly locale: LocaleRouteNormalizer | undefined
}

constructor(
Expand All @@ -30,6 +32,9 @@ export class BaseRequestAdapter<ServerRequest extends BaseNextRequest>
basePath: this.nextConfig.basePath
? new BasePathPathnameNormalizer(this.nextConfig.basePath)
: undefined,
locale: i18nProvider
? new LocaleRouteNormalizer(i18nProvider)
: undefined,
}
}

Expand All @@ -54,8 +59,8 @@ export class BaseRequestAdapter<ServerRequest extends BaseNextRequest>
}
}

if (this.i18nProvider) {
const { pathname } = this.i18nProvider.analyze(url.pathname)
if (this.normalizers.locale) {
const pathname = this.normalizers.locale.normalize(url.pathname)
if (pathname !== url.pathname) {
url.pathname = pathname
addRequestMeta(req, 'didStripLocale', true)
Expand Down

0 comments on commit a01691d

Please sign in to comment.