view benchmark/bun-http-framework-benchmark/src/bun/bun-web-standard.ts @ 275:78699f810817

Add Qwen3-VL and WebRTC dictation services Add Bazel targets for the CUDA-backed Qwen3-VL server and a local WebRTC faster-whisper dictation service. Co-authored-by: Copilot <[email protected]> Copilot-Session: e3d8cb06-6c95-4ae0-9757-651d3796ab00
author MrJuneJune <me@mrjunejune.com>
date Mon, 17 Aug 2026 10:58:47 -0700
parents a8976a008a9d
children
line wrap: on
line source

// Using Web Standard API to handle
// This is likely an real-world implementation
// if you're using pure Bun HTTP server
Bun.serve({
	port: 3000,
	fetch: async (request) => {
		const url = new URL(request.url)

		switch (request.method) {
			case 'GET':
				switch (url.pathname) {
					case '/':
						return new Response('Hi')
				}

				if (url.pathname.startsWith('/id/')) {
					const [id, rest] = url.pathname.slice(4).split('/')

					if (!rest)
						return new Response(
							`${id} ${url.searchParams.get('name')}`,
							{
								headers: {
									'x-powered-by': 'benchmark'
								}
							}
						)
				}

				return new Response('Not Found', {
					status: 404
				})

			case 'POST':
				switch (url.pathname) {
					case '/json':
						return Response.json(await request.json())

					default:
						return new Response('Not Found', {
							status: 404
						})
				}

			default:
				return new Response('Not Found', {
					status: 404
				})
		}
	}
})