Menu

Node.js Vercel Functions now support request cancellation - Vercel
📰
0

Node.js Vercel Functions now support request cancellation - Vercel

Vercel News·Craig Andrews·4 days ago
#XMd726Ax
Reading 0:00
15s threshold

Request cancellation is now supported at the route level; you have to manually enable it in vercel.json . Read more . Vercel Functions using Node.js can now detect when a request is cancelled and stop execution before completion. This includes actions like navigating away, closing a tab, or hitting stop on an AI chat to terminate compute processing early. This reduces unnecessary compute, token generation, and sending data the user never see. You can listen for cancellation using Request.signal.aborted or the abort event: export const GET = async ( req : Request ) => { const abortController = new AbortController ( ) ; req . signal . addEventListener ( "abort" , ( ) => { console . log ( "request aborted" ) ; abortController . abort ( ) ; } ) ; const res = await fetch ( "https://my-backend-service.example.com" , { headers : { Authorization : ` Bearer ${ process . env . AUTH_TOKEN } ` , } , signal : abortController . signal , } ) ; return new Response ( res . body , { status : res .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More