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

Error "page not found" in the middleware when accessing the API #1011

Closed
3 tasks done
dixakman opened this issue Apr 20, 2024 · 1 comment
Closed
3 tasks done

Error "page not found" in the middleware when accessing the API #1011

dixakman opened this issue Apr 20, 2024 · 1 comment
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@dixakman
Copy link

dixakman commented Apr 20, 2024

Description

Error "page not found" in the middleware when accessing the API

Code middleware:
`
export default async function middleware(request: NextRequest) {

console.log("OK")


const handleI18nRouting = createIntlMiddleware({
    locales,
    defaultLocale,
    pathnames,
    localePrefix
});
const response = handleI18nRouting(request);

response.headers.set('x-your-custom-locale', defaultLocale);


return response;

}
`

Show "OK", but the error is "Page not found"

blocks the api, but allows a separate path
Config middleware:
`
export const config = {
matcher: [
// Enable a redirect to a matching locale at the root
'/',

    // Set a cookie to remember the previous locale for
    // all requests that have a locale prefix
    '/(ru|en)/:path*',

    // Enable redirects that add missing locales
    // (e.g. `/pathnames` -> `/en/pathnames`)
    '/((?!api|_next|_vercel|.*\\..*).*)',

    '/api/chat/all'
]

};
`

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/amannn/next-intl-bug-repro-app-router

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Click on …
  3. See error: …

Expected behaviour

show response from api

@dixakman dixakman added bug Something isn't working unconfirmed Needs triage. labels Apr 20, 2024
@amannn
Copy link
Owner

amannn commented Apr 22, 2024

Closing, since no reproduction was provided.

As you've also pointed out, your matcher likely has an issue—this is controlled in your user code and not by next-intl. This might be relevant for you: https://next-intl-docs.vercel.app/docs/routing/middleware#matcher-config

@amannn amannn closed this as completed Apr 22, 2024
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