Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cannot understand how to merge next-intl middleware with nextjs/platform #1069

Closed
3 tasks done
timbit123 opened this issue May 13, 2024 · 3 comments
Closed
3 tasks done
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@timbit123
Copy link

Description

Hello,

I'm working on a project base from https://github.com/vercel/platforms where you can host multiple website using the domain as a dynamic value.

so when I'm on a public website we do a url rewrite like this in the middleware,ts:L72

return NextResponse.rewrite(new URL(`/${hostname}${path}`, req.url));

I'm trying to combine this with intlMiddleware but I cannot get it to work.
Any help would be really appreciated.
Thank you!

Verifications

  • I've verified that the problem I'm experiencing isn't covered in the docs.
  • I've searched for similar, existing issues on GitHub and Stack Overflow.
  • I've compared my app to a working example to look for differences.

Mandatory reproduction URL

https://github.com/vercel/platforms

Reproduction description

Steps to reproduce:

  1. clone the project
  2. run the project with a domain
  3. Be able to have locale with domain (which is dynamic based on the subdomain or other)

Expected behaviour

I would like to be able to do a rewrite url to look like this

  return NextResponse.rewrite(new URL(`/${locale}/${hostname}${path}`, req.url));
@timbit123 timbit123 added bug Something isn't working unconfirmed Needs triage. labels May 13, 2024
@timbit123
Copy link
Author

timbit123 commented May 13, 2024

I came up with this. it would be great if someone could give his opinion.

export default async function middleware(req: NextRequest) {
  // ...
  const [, locale, ...segments] = req.nextUrl.pathname.split("/");
  let intlResponse = intlMiddleware(req);
  if (!locales.includes(locale)) {
    return intlResponse;
  }
  return NextResponse.rewrite(new URL(`/${locale}/${domain}/${segments}`, req.url), intlResponse);
}

@amannn
Copy link
Owner

amannn commented May 14, 2024

This is discussed in #653, please have a look there for related discussions and options you have.

@amannn
Copy link
Owner

amannn commented May 14, 2024

I also made a note about your use case in #653, thanks for including details about your use case!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants