0.1.2 • Published 8 months ago

bun-conductor v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

bun-conductor

Extremely basic and simple router module for Bun.

Usage

import Router from 'bun-conductor'
const router = new Router();

router.serveAPI();
router.post('path', handler);

Bun.serve({
  fetch(req) { return router.handle(req); },
});

The handler must return a Response object.

Static Files

Allows a folder to be served as static files.

import Router from 'bun-conductor'
const router = new Router();

router.serveClient('client');

Bun.serve({
  fetch(req) { return router.handle(req); },
});

Sub Paths

import Router from 'bun-conductor'
const router = new Router();

// Define the new router
const testRouter = new Router();
testRouter.get('hello-world', () => {
  return new Response('Hello World from /api/test/hello-world');
})

// Define the new segment and its router
router.use('test', testRouter)

// Serve the API
router.serveAPI();

// Run the server
Bun.serve({
  fetch(req) { return router.handle(req); },
});
0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago