next-intl 4.0.0-beta-22cf1cd → 4.0.0-beta-1a5e0ec

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,14 @@ function createMiddleware(routing) {
59
59
  urlObj.host = redirectDomain;
60
60
  if (request.headers.get('x-forwarded-host')) {
61
61
  urlObj.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol;
62
- urlObj.port = request.headers.get('x-forwarded-port') ?? '';
62
+ const redirectDomainPort = redirectDomain.split(':')[1];
63
+ urlObj.port = redirectDomainPort ?? request.headers.get('x-forwarded-port') ?? '';
63
64
  }
64
65
  }
65
66
  if (request.nextUrl.basePath) {
66
67
  urlObj.pathname = applyBasePath(urlObj.pathname, request.nextUrl.basePath);
67
68
  }
69
+ hasRedirected = true;
68
70
  return NextResponse.redirect(urlObj.toString());
69
71
  }
70
72
  const unprefixedExternalPathname = getNormalizedPathname(externalPathname, resolvedRouting.locales, resolvedRouting.localePrefix);
@@ -73,6 +75,7 @@ function createMiddleware(routing) {
73
75
  const isUnprefixedRouting = resolvedRouting.localePrefix.mode === 'never' || hasMatchedDefaultLocale && resolvedRouting.localePrefix.mode === 'as-needed';
74
76
  let response;
75
77
  let internalTemplateName;
78
+ let hasRedirected;
76
79
  let unprefixedInternalPathname = unprefixedExternalPathname;
77
80
  const pathnames = resolvedRouting.pathnames;
78
81
  if (pathnames) {
@@ -140,7 +143,7 @@ function createMiddleware(routing) {
140
143
  }
141
144
  }
142
145
  syncCookie(request, response, locale, resolvedRouting, domain);
143
- if (resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
146
+ if (!hasRedirected && resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
144
147
  response.headers.set('Link', getAlternateLinksHeaderValue({
145
148
  routing: resolvedRouting,
146
149
  localizedPathnames: internalTemplateName != null && pathnames ? pathnames[internalTemplateName] : undefined,
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{receiveRoutingConfig as t}from"../routing/config.js";import{HEADER_LOCALE_NAME as r}from"../shared/constants.js";import{matchesPathname as o,normalizeTrailingSlash as a,getLocalePrefix as l}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as p,getBestMatchingDomain as u,applyBasePath as U,getLocaleAsPrefix as P}from"./utils.js";function g(g){const v=t(g);return function(t){let g;try{g=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const L=c(g),{domain:j,locale:w}=s(v,t.headers,t.cookies,L),k=j?j.defaultLocale===w:w===v.defaultLocale,b=v.domains?.filter((e=>d(w,e)))||[],y=null!=v.domains&&!j;function R(o){const a=new URL(o,t.url);t.nextUrl.basePath&&(a.pathname=U(a.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);return l.set(r,w),e.rewrite(a,{request:{headers:l}})}function q(r,o){const l=new URL(r,t.url);if(l.pathname=a(l.pathname),b.length>0&&!o&&j){const e=u(j,w,b);e&&(o=e.domain,e.defaultLocale===w&&"as-needed"===v.localePrefix.mode&&(l.pathname=f(l.pathname,v.locales,v.localePrefix)))}return o&&(l.host=o,t.headers.get("x-forwarded-host")&&(l.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol,l.port=t.headers.get("x-forwarded-port")??"")),t.nextUrl.basePath&&(l.pathname=U(l.pathname,t.nextUrl.basePath)),e.redirect(l.toString())}const H=f(L,v.locales,v.localePrefix),z=m(L,v.locales,v.localePrefix),A=null!=z,C="never"===v.localePrefix.mode||k&&"as-needed"===v.localePrefix.mode;let I,S,V=H;const B=v.pathnames;if(B){let e;if([e,S]=h(B,H,w),S){const r=B[S],a="string"==typeof r?r:r[w];if(o(a,H))V=x(H,a,S);else{let o;o=e?"string"==typeof r?r:r[e]:S;const n=C?void 0:l(w,v.localePrefix),s=x(H,o,a);I=q(p(s,n,t.nextUrl.search))}}}if(!I)if("/"!==V||A){const e=p(V,P(w),t.nextUrl.search);if(A){const r=p(H,z.prefix,t.nextUrl.search);if("never"===v.localePrefix.mode)I=q(p(H,void 0,t.nextUrl.search));else if(z.exact)if(k&&C)I=q(p(H,void 0,t.nextUrl.search));else if(v.domains){const t=u(j,z.locale,b);I=j?.domain===t?.domain||y?R(e):q(r,t?.domain)}else I=R(e);else I=q(r)}else I=C?R(e):q(p(H,l(w,v.localePrefix),t.nextUrl.search))}else I=C?R(p(V,P(w),t.nextUrl.search)):q(p(H,l(w,v.localePrefix),t.nextUrl.search));return i(t,I,w,v,j),"never"!==v.localePrefix.mode&&v.alternateLinks&&v.locales.length>1&&I.headers.set("Link",n({routing:v,localizedPathnames:null!=S&&B?B[S]:void 0,request:t,resolvedLocale:w})),I}}export{g as default};
1
+ import{NextResponse as e}from"next/server";import{receiveRoutingConfig as t}from"../routing/config.js";import{HEADER_LOCALE_NAME as r}from"../shared/constants.js";import{matchesPathname as o,normalizeTrailingSlash as a,getLocalePrefix as l}from"../shared/utils.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as m,getInternalTemplate as h,formatTemplatePathname as x,formatPathname as p,getBestMatchingDomain as u,applyBasePath as U,getLocaleAsPrefix as P}from"./utils.js";function g(g){const v=t(g);return function(t){let g;try{g=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const L=c(g),{domain:j,locale:w}=s(v,t.headers,t.cookies,L),k=j?j.defaultLocale===w:w===v.defaultLocale,b=v.domains?.filter((e=>d(w,e)))||[],y=null!=v.domains&&!j;function R(o){const a=new URL(o,t.url);t.nextUrl.basePath&&(a.pathname=U(a.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);return l.set(r,w),e.rewrite(a,{request:{headers:l}})}function q(r,o){const l=new URL(r,t.url);if(l.pathname=a(l.pathname),b.length>0&&!o&&j){const e=u(j,w,b);e&&(o=e.domain,e.defaultLocale===w&&"as-needed"===v.localePrefix.mode&&(l.pathname=f(l.pathname,v.locales,v.localePrefix)))}if(o&&(l.host=o,t.headers.get("x-forwarded-host"))){l.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol;const e=o.split(":")[1];l.port=e??t.headers.get("x-forwarded-port")??""}return t.nextUrl.basePath&&(l.pathname=U(l.pathname,t.nextUrl.basePath)),V=!0,e.redirect(l.toString())}const H=f(L,v.locales,v.localePrefix),z=m(L,v.locales,v.localePrefix),A=null!=z,C="never"===v.localePrefix.mode||k&&"as-needed"===v.localePrefix.mode;let I,S,V,B=H;const D=v.pathnames;if(D){let e;if([e,S]=h(D,H,w),S){const r=D[S],a="string"==typeof r?r:r[w];if(o(a,H))B=x(H,a,S);else{let o;o=e?"string"==typeof r?r:r[e]:S;const n=C?void 0:l(w,v.localePrefix),s=x(H,o,a);I=q(p(s,n,t.nextUrl.search))}}}if(!I)if("/"!==B||A){const e=p(B,P(w),t.nextUrl.search);if(A){const r=p(H,z.prefix,t.nextUrl.search);if("never"===v.localePrefix.mode)I=q(p(H,void 0,t.nextUrl.search));else if(z.exact)if(k&&C)I=q(p(H,void 0,t.nextUrl.search));else if(v.domains){const t=u(j,z.locale,b);I=j?.domain===t?.domain||y?R(e):q(r,t?.domain)}else I=R(e);else I=q(r)}else I=C?R(e):q(p(H,l(w,v.localePrefix),t.nextUrl.search))}else I=C?R(p(B,P(w),t.nextUrl.search)):q(p(H,l(w,v.localePrefix),t.nextUrl.search));return i(t,I,w,v,j),!V&&"never"!==v.localePrefix.mode&&v.alternateLinks&&v.locales.length>1&&I.headers.set("Link",n({routing:v,localizedPathnames:null!=S&&D?D[S]:void 0,request:t,resolvedLocale:w})),I}}export{g as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "4.0.0-beta-22cf1cd",
3
+ "version": "4.0.0-beta-1a5e0ec",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -112,7 +112,7 @@
112
112
  "dependencies": {
113
113
  "@formatjs/intl-localematcher": "^0.5.4",
114
114
  "negotiator": "^1.0.0",
115
- "use-intl": "4.0.0-beta-22cf1cd"
115
+ "use-intl": "4.0.0-beta-1a5e0ec"
116
116
  },
117
117
  "peerDependencies": {
118
118
  "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
@@ -124,5 +124,5 @@
124
124
  "optional": true
125
125
  }
126
126
  },
127
- "gitHead": "4c488a143d58b57453b167b59b8061e3263016dc"
127
+ "gitHead": "6be2a42842d65730cf3e1a6a9bdfbc8b95cc5c18"
128
128
  }