Menu

Bun runtime for Vercel Functions now accepts Bun.serve as an entrypoint - Vercel
📰

Bun runtime for Vercel Functions now accepts Bun.serve as an entrypoint - Vercel

Vercel News·Florentin Eckl·5 days ago
#DIgT2VuC
#vercel#server#request#websocket#response
Reading 0:00
15s threshold

The Bun runtime for Vercel Functions now supports Bun.serve() as a function entrypoint, including WebSocket handlers. The server you run locally with Bun deploys as-is, without being wrapped in a framework.

Enable the runtime by setting "bunVersion": "1.x" in vercel.json .

Copy link to heading Deploy a routes-based server

Create a server with a routes map in server.ts at the project root.

Bun . serve ( {

routes : {

"/api/boolean" : ( ) => Response . json ( { success : true } ) ,

"/api/users/:id" : ( request ) => Response . json ( { user : request . params . id } ) ,

"/*" : ( ) => new Response ( "api catch-all" ) ,

} ,

} ) ;

A Bun.serve server deployed to Vercel with static, dynamic, and wildcard routes

Copy link to heading Accept WebSocket connections

Add a websocket handler and call server.upgrade(request) in fetch to upgrade matching requests. The rest of the server stays the same.

Bun . serve ( {

routes : {

"/health" : Response .…

Continue reading — create a free account

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