I can't response into a server action from middleware
Unanswered
Polar bear posted this in #help-forum
Polar bearOP
export async function middleware(request: NextRequest) {
const NEXT_ACTION = headers().get("next-action")
if (NEXT_ACTION === ContactActions.Mail) {
console.log("Is mail servera ction")
return NextResponse.json({
status: "error",
message: "You have reached the limit"
}, { status: 429 })
}
}
export const config = {
matcher: '/:path*',
}I'm trying to do some kind of ratelimiting but I coudn't respond to server actions from middleware to access it in the form and getting undefined
6 Replies
@Polar bear ts
export async function middleware(request: NextRequest) {
const NEXT_ACTION = headers().get("next-action")
if (NEXT_ACTION === ContactActions.Mail) {
console.log("Is mail servera ction")
return NextResponse.json({
status: "error",
message: "You have reached the limit"
}, { status: 429 })
}
}
export const config = {
matcher: '/:path*',
}
I'm trying to do some kind of ratelimiting but I coudn't respond to server actions from middleware to access it in the form and getting undefined
try this matcher
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};@gin try this matcher
typescript
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
};
Polar bearOP
What's the relation?
My problem is I can't overwrite the response of the server action
I want the server action to respond with rate limit response instead of responding with it's normal response
@Polar bear My problem is I can't overwrite the response of the server action
is your if statement triggering tho
Polar bearOP
Yes