A minimal, fast, and type-safe web server template built with Bun and TypeScript. Features file-system based routing, static file serving, WebSocket support, and structured logging.
Find a file
creations 2eebc3126a
All checks were successful
Code quality checks / biome (push) Successful in 10s
- Remove Bunserver and just use buns type
- Stop logging every start aswell as available routes
2025-06-03 21:03:28 -04:00
.forgejo/workflows add workflow 2025-04-11 04:08:17 -04:00
config rename config 2025-06-02 20:42:47 -04:00
public/assets first commit 2024-12-21 19:24:48 -05:00
src - Remove Bunserver and just use buns type 2025-06-03 21:03:28 -04:00
types - Remove Bunserver and just use buns type 2025-06-03 21:03:28 -04:00
.editorconfig editor configs? 2024-12-21 21:03:32 -05:00
.env forgot to remove from env 2025-06-02 20:37:43 -04:00
.gitattributes editor configs? 2024-12-21 21:03:32 -05:00
.gitignore - Remove Bunserver and just use buns type 2025-06-03 21:03:28 -04:00
biome.json Migrate to @atums/echo logger and improve project structure 2025-06-02 20:34:50 -04:00
LICENSE Migrate to @atums/echo logger and improve project structure 2025-06-02 20:34:50 -04:00
logger.json Migrate to @atums/echo logger and improve project structure 2025-06-02 20:34:50 -04:00
package.json Migrate to @atums/echo logger and improve project structure 2025-06-02 20:34:50 -04:00
README.md Migrate to @atums/echo logger and improve project structure 2025-06-02 20:34:50 -04:00
tsconfig.json rename config 2025-06-02 20:42:47 -04:00

Bun Frontend Template

A minimal, fast, and type-safe web server template built with Bun and TypeScript. Features file-system based routing, static file serving, WebSocket support, and structured logging.

Configuration

Environment Variables

Variable Description Default Required
HOST Server host address 0.0.0.0
PORT Server port 8080
NODE_ENV Environment mode production

Creating Routes

Routes are automatically generated from files in src/routes/. Each route file exports:

// src/routes/example.ts
const routeDef: RouteDef = {
  method: "GET",                    // HTTP method(s)
  accepts: "application/json",      // Content-Type validation
  returns: "application/json",      // Response Content-Type
  needsBody?: "json" | "multipart"  // Optional body parsing, dont include if neither are required
};

async function handler(
  request: ExtendedRequest,
  requestBody: unknown,
  server: BunServer
): Promise<Response> {
  return Response.json({ message: "Hello World" });
}

export { handler, routeDef };

Route Features

  • Method Validation - Automatic HTTP method checking
  • Content-Type Validation - Request/response content type enforcement
  • Body Parsing - Automatic JSON/FormData parsing
  • Query Parameters - Automatic query string parsing
  • URL Parameters - Next.js-style dynamic routes ([id].ts)

Static Files

Place files in public/ directory

Custom Public Files

Files in public/custom/ are served with security checks:

  • Path traversal protection
  • Content-type detection
  • Direct file serving

License

This project is licensed under the BSD-3-Clause - see the LICENSE file for details.

Dependencies

  • @atums/echo - Structured logging with daily rotation
  • Bun - Fast JavaScript runtime and bundler
  • TypeScript - Type-safe JavaScript
  • Biome - Fast formatter and linter