405 Method not allowed but the route method is created
Unanswered
Mini Satin posted this in #help-forum
Mini SatinOP
I am getting 405 Method not allowed but the route handler method is created.
6 Replies
@Mini Satin I am getting 405 Method not allowed but the route handler method is created.
show your code for route handler
@riský show your code for route handler
Mini SatinOP
The error was within the middleware, I am trying to use next-intl
we can't help you without any code... is there some that generated the error?
@riský we can't help you without any code... is there some that generated the error?
Mini SatinOP
sorry I thought I sent the code
middleware.ts
I have two folders to api
|
- [locales]
-api
-routes...
|
- api
-routes...
the one inside locales does not work and I get 405
import { NextRequest } from "next/server";
import { withAuth } from "next-auth/middleware";
import createIntlMiddleware from "next-intl/middleware";
import { localePrefix, locales } from "./i18n.config";
const publicPages = ["/", "/login"];
const intlMiddleware = createIntlMiddleware({
locales,
localePrefix,
defaultLocale: locales[0],
});
const authMiddleware = withAuth((req) => intlMiddleware(req), {
callbacks: {
authorized: ({ token }) => token != null,
},
pages: {
signIn: "/login",
},
});
export default function middleware(req: NextRequest) {
const publicPathnameRegex = RegExp(
`^(/(${locales.join("|")}))?(${publicPages
.flatMap((p) => (p === "/" ? ["", "/"] : p))
.join("|")})/?$`,
"i",
);
const isPublicPage = publicPathnameRegex.test(req.nextUrl.pathname);
if (isPublicPage) {
return intlMiddleware(req);
} else {
return (authMiddleware as any)(req);
}
}
export const config = {
matcher: [
"/",
"/(en-US|en|it|fr|pt-BR|zh)/:path*",
"/((?!api|_next/static|_next/image|favicon.ico).*)",
],
};I have two folders to api
|
- [locales]
-api
-routes...
|
- api
-routes...
the one inside locales does not work and I get 405