Routing problem, got 404 while the route is present on the directory. #75091
-
SummaryI’ve recently taken over the development of a project started by someone else, and I’ve encountered this weird issue regarding the app routing that I need some help with. When testing the project with postman, and hit the '/api/file/upload' it returns 404 error. But when I hit the API with '/file/upload/' it returns 200. I've read the similar issue with this #74213. Any help for this issue? Thank you. Additional informationTree of the project :
/src
└── /app
└── /api
└── /file
└── /upload
└── route.ts
----------------------------------------------------------------
The Middleware
export async function middleware(request: NextRequest) {
if (request.nextUrl.pathname.includes("/api") || request.nextUrl.pathname.includes("/app")) {
if (request.cookies.get("appSession")) {
return NextResponse.next()
} else {
return NextResponse.error()
}
}
if (request.cookies.get("appSession")) {
return verifyJwt(request.cookies.get("appSession")!.value)
}
if (!request.cookies.get("appSession")) {
return login()
}
const requestheader = new Headers(request.headers)
requestheader.set("X-Pathname", request.nextUrl.pathname)
return NextResponse.next({
request: {
headers: requestheader
}
})
}
----------------------------------------------------------------
The next.config.mjs
const rulesToProcess = [/\.m?ts/, /\.(ts|cts|mts)$/].map(String);
const dirToIgnore = /src\/lib\/ui-temp/;
/** @type {import('next').NextConfig} */
const nextConfig = {
pageExtensions: ["ts", "tsx"],
reactStrictMode: false,
experimental: {
instrumentationHook: true,
},
webpack: (config) => {
config.module.rules = config.module.rules.map((rule) => {
if (rule !== "..." && rulesToProcess.indexOf(String(rule.test)) > -1) {
rule.exclude = [dirToIgnore];
}
return rule;
});
return config;
}
};
export default nextConfig; ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
What's the Next.js version? weird that the middleware checks for |
Beta Was this translation helpful? Give feedback.
-
Hi, In this case, we were trying to avoid registering a new callback for oauth. So we just decided to make a new endpoint (that being TLDR: we were making a new endpoint outside the |
Beta Was this translation helpful? Give feedback.
Hi, In this case, we were trying to avoid registering a new callback for oauth. So we just decided to make a new endpoint (that being
/app/
) that just redirects to our real callback endpoint. In hindsight, we should've just redirect the request from the middleware instead.TLDR: we were making a new endpoint outside the
/api/
endpoint (in our case was/app/callback
) results in behaviour like this.