next-intl 4.10.0 → 4.10.1

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.
@@ -54,6 +54,7 @@ function createMiddleware(routing) {
54
54
  }
55
55
  function redirect(url, redirectDomain) {
56
56
  const urlObj = new URL(url, request.url);
57
+ const forwardedHost = request.headers.get('x-forwarded-host');
57
58
  urlObj.pathname = normalizeTrailingSlash(urlObj.pathname);
58
59
  if (domainsConfig.length > 0 && !redirectDomain && domain) {
59
60
  const bestMatchingDomain = getBestMatchingDomain(domain, locale, domainsConfig);
@@ -65,13 +66,19 @@ function createMiddleware(routing) {
65
66
  }
66
67
  }
67
68
  }
68
- if (redirectDomain) {
69
- urlObj.host = redirectDomain;
70
- if (request.headers.get('x-forwarded-host')) {
71
- urlObj.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol;
72
- const redirectDomainPort = redirectDomain.split(':')[1];
73
- urlObj.port = redirectDomainPort ?? request.headers.get('x-forwarded-port') ?? '';
74
- }
69
+
70
+ // Priority for redirect origins:
71
+ // 1) Explicit domain from `redirectDomain`
72
+ // 2) Reverse proxy host from `x-forwarded-host`
73
+ // 3) Fallback to `request.url`
74
+ const redirectHost = redirectDomain ?? forwardedHost;
75
+ if (redirectHost) {
76
+ urlObj.host = redirectHost;
77
+ }
78
+ if (forwardedHost) {
79
+ urlObj.protocol = request.headers.get('x-forwarded-proto') ?? request.nextUrl.protocol;
80
+ const redirectHostPort = redirectHost?.split(':')[1];
81
+ urlObj.port = redirectHostPort ?? request.headers.get('x-forwarded-port') ?? '';
75
82
  }
76
83
  if (request.nextUrl.basePath) {
77
84
  urlObj.pathname = applyBasePath(urlObj.pathname, request.nextUrl.basePath);
@@ -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 a,normalizeTrailingSlash as o,getLocalePrefix as n,getLocalizedTemplate as l}from"../shared/utils.js";import s from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import c from"./syncCookie.js";import{sanitizePathname as d,isLocaleSupportedOnDomain as f,getNormalizedPathname as m,getPathnameMatch as h,getInternalTemplate as x,formatTemplatePathname as p,formatPathname as u,getBestMatchingDomain as U,applyBasePath as P,getLocaleAsPrefix as g}from"./utils.js";function v(v){const L=t(v);return function(t){let v;try{v=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const j=d(v),{domain:w,locale:k}=i(L,t.headers,t.cookies,j),b=w?w.defaultLocale===k:k===L.defaultLocale,q=L.domains?.filter((e=>f(k,e)))||[],R=null!=L.domains&&!w;function y(a){const n=new URL(a,t.url);t.nextUrl.basePath&&(n.pathname=P(n.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);l.set(r,k);return o(t.nextUrl.pathname)!==o(n.pathname)?e.rewrite(n,{request:{headers:l}}):e.next({request:{headers:l}})}function H(r,a){const n=new URL(r,t.url);if(n.pathname=o(n.pathname),q.length>0&&!a&&w){const e=U(w,k,q);if(e){a=e.domain;const t=e.localePrefix||L.localePrefix.mode;e.defaultLocale===k&&"as-needed"===t&&(n.pathname=m(n.pathname,L.locales,L.localePrefix))}}if(a&&(n.host=a,t.headers.get("x-forwarded-host"))){n.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol;const e=a.split(":")[1];n.port=e??t.headers.get("x-forwarded-port")??""}return t.nextUrl.basePath&&(n.pathname=P(n.pathname,t.nextUrl.basePath)),V=!0,e.redirect(n.toString())}const z=m(j,L.locales,L.localePrefix),A=h(j,L.locales,L.localePrefix,w),C=null!=A,I=w?.localePrefix||L.localePrefix.mode,N="never"===I||b&&"as-needed"===I;let S,T,V,B=z;const D=L.pathnames;if(D){let e;if([e,T]=x(D,z,k),T){const r=D[T],o=l(r,k,T);if(a(o,z))B=p(z,o,T);else{let a;a=e?l(r,e,T):T;const s=N?void 0:n(k,L.localePrefix),i=p(z,a,o);S=H(u(i,s,t.nextUrl.search))}}}if(!S)if("/"!==B||C){const e=u(B,g(k),t.nextUrl.search);if(C){const r=u(z,A.prefix,t.nextUrl.search);if("never"===I)S=H(u(z,void 0,t.nextUrl.search));else if(A.exact)if(b&&N)S=H(u(z,void 0,t.nextUrl.search));else if(L.domains){const t=U(w,A.locale,q);S=w?.domain===t?.domain||R?y(e):H(r,t?.domain)}else S=y(e);else S=H(r)}else S=N?y(e):H(u(z,n(k,L.localePrefix),t.nextUrl.search))}else S=N?y(u(B,g(k),t.nextUrl.search)):H(u(z,n(k,L.localePrefix),t.nextUrl.search));return c(t,S,k,L,w),!V&&"never"!==I&&L.alternateLinks&&L.locales.length>1&&S.headers.set("Link",s({routing:L,internalTemplateName:T,localizedPathnames:null!=T&&D?D[T]:void 0,request:t,resolvedLocale:k})),S}}export{v 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 a,normalizeTrailingSlash as o,getLocalePrefix as n,getLocalizedTemplate as l}from"../shared/utils.js";import s from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import c from"./syncCookie.js";import{sanitizePathname as d,isLocaleSupportedOnDomain as f,getNormalizedPathname as m,getPathnameMatch as h,getInternalTemplate as x,formatTemplatePathname as p,formatPathname as u,getBestMatchingDomain as U,applyBasePath as P,getLocaleAsPrefix as g}from"./utils.js";function v(v){const L=t(v);return function(t){let v;try{v=decodeURI(t.nextUrl.pathname)}catch{return e.next()}const j=d(v),{domain:w,locale:k}=i(L,t.headers,t.cookies,j),b=w?w.defaultLocale===k:k===L.defaultLocale,q=L.domains?.filter((e=>f(k,e)))||[],R=null!=L.domains&&!w;function y(a){const n=new URL(a,t.url);t.nextUrl.basePath&&(n.pathname=P(n.pathname,t.nextUrl.basePath));const l=new Headers(t.headers);l.set(r,k);return o(t.nextUrl.pathname)!==o(n.pathname)?e.rewrite(n,{request:{headers:l}}):e.next({request:{headers:l}})}function H(r,a){const n=new URL(r,t.url),l=t.headers.get("x-forwarded-host");if(n.pathname=o(n.pathname),q.length>0&&!a&&w){const e=U(w,k,q);if(e){a=e.domain;const t=e.localePrefix||L.localePrefix.mode;e.defaultLocale===k&&"as-needed"===t&&(n.pathname=m(n.pathname,L.locales,L.localePrefix))}}const s=a??l;if(s&&(n.host=s),l){n.protocol=t.headers.get("x-forwarded-proto")??t.nextUrl.protocol;const e=s?.split(":")[1];n.port=e??t.headers.get("x-forwarded-port")??""}return t.nextUrl.basePath&&(n.pathname=P(n.pathname,t.nextUrl.basePath)),V=!0,e.redirect(n.toString())}const z=m(j,L.locales,L.localePrefix),A=h(j,L.locales,L.localePrefix,w),C=null!=A,I=w?.localePrefix||L.localePrefix.mode,N="never"===I||b&&"as-needed"===I;let S,T,V,B=z;const D=L.pathnames;if(D){let e;if([e,T]=x(D,z,k),T){const r=D[T],o=l(r,k,T);if(a(o,z))B=p(z,o,T);else{let a;a=e?l(r,e,T):T;const s=N?void 0:n(k,L.localePrefix),i=p(z,a,o);S=H(u(i,s,t.nextUrl.search))}}}if(!S)if("/"!==B||C){const e=u(B,g(k),t.nextUrl.search);if(C){const r=u(z,A.prefix,t.nextUrl.search);if("never"===I)S=H(u(z,void 0,t.nextUrl.search));else if(A.exact)if(b&&N)S=H(u(z,void 0,t.nextUrl.search));else if(L.domains){const t=U(w,A.locale,q);S=w?.domain===t?.domain||R?y(e):H(r,t?.domain)}else S=y(e);else S=H(r)}else S=N?y(e):H(u(z,n(k,L.localePrefix),t.nextUrl.search))}else S=N?y(u(B,g(k),t.nextUrl.search)):H(u(z,n(k,L.localePrefix),t.nextUrl.search));return c(t,S,k,L,w),!V&&"never"!==I&&L.alternateLinks&&L.locales.length>1&&S.headers.set("Link",s({routing:L,internalTemplateName:T,localizedPathnames:null!=T&&D?D[T]:void 0,request:t,resolvedLocale:k})),S}}export{v as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "4.10.0",
3
+ "version": "4.10.1",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -127,11 +127,11 @@
127
127
  "@formatjs/intl-localematcher": "^0.8.1",
128
128
  "@parcel/watcher": "^2.4.1",
129
129
  "@swc/core": "^1.15.2",
130
- "icu-minify": "^4.10.0",
130
+ "icu-minify": "^4.10.1",
131
131
  "negotiator": "^1.0.0",
132
- "next-intl-swc-plugin-extractor": "^4.10.0",
132
+ "next-intl-swc-plugin-extractor": "^4.10.1",
133
133
  "po-parser": "^2.1.1",
134
- "use-intl": "^4.10.0"
134
+ "use-intl": "^4.10.1"
135
135
  },
136
136
  "peerDependencies": {
137
137
  "next": "^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0",
@@ -142,5 +142,5 @@
142
142
  "optional": true
143
143
  }
144
144
  },
145
- "gitHead": "d4648b884c609400b53da58ab0def5feb22ab654"
145
+ "gitHead": "11d9ce823f9901041eaeb620859607aadf49ef3f"
146
146
  }