You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, middleware gets bypassed/ignored when the middleware.(ts|js) file is placed in the src folder, something that is supported according to Next.js documentation.
export function middleware(request) {
throw new Error("This never runs");
}
mkdir -p src/app/api/test
touch src/app/api/test/route.ts
src/app/api/test/route.ts contents:
import { NextResponse } from "next/server";
export function GET() {
return NextResponse.json(
{
success: "middleware not called",
},
{ status: 200 }
);
}
yarn build && yarn start
curl http://localhost:3000/api/test
Expected Result
The curl request never reaches the src/api/test/route.ts route due to middleware throwing an error.
According to Next.js's documentation on middleware conventions the middleware.ts file should be able to be placed in both the root and in the src directory.
Actual Result
The curl request reaches the src/api/test/route.ts route.
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
7.64.0
Framework Version
7.64.0
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
Basically, middleware gets bypassed/ignored when the middleware.(ts|js) file is placed in the
src
folder, something that is supported according to Next.js documentation.npx create-next-app --example reproduction-template reproduction-app
cd reproduction-app
npx @sentry/wizard -i nextjs
mkdir src
mv app src/
touch src/middleware.ts
mkdir -p src/app/api/test
touch src/app/api/test/route.ts
yarn build && yarn start
curl http://localhost:3000/api/test
Expected Result
The curl request never reaches the
src/api/test/route.ts
route due to middleware throwing an error.According to Next.js's documentation on middleware conventions the middleware.ts file should be able to be placed in both the root and in the src directory.
Actual Result
The curl request reaches the
src/api/test/route.ts
route.The text was updated successfully, but these errors were encountered: