Skip to content

Serving Files

Bun

Serving static files with Byte on Bun.

// Registering routes for serving
const publicDir = `${import.meta.dir}/public/`;
app.any('/*', (ctx) => ctx.body(Bun.file(publicDir + ctx.params.$)));
// Serving
Bun.serve({
// Get the fetch function
fetch: app.fetch,
// Handle uncaught error, which includes file not found
error: send.body(null, { status: 404 })
});

Deno

Serving static files with Byte on Deno.

import { serveDir } from 'jsr:@std/http/file-server';
const serveDirOptions = { fsRoot: `${import.meta.dir}/public/` };
app.any('/*', (ctx) => serveDir(ctx.req, serveDirOptions));