kwhitley / itty-router

A little router.
MIT License
1.69k stars 77 forks source link

DRAFT: adds flow options to basic Router, as well as custom option/object passthrough #212

Closed kwhitley closed 3 months ago

kwhitley commented 6 months ago

Description

This adds support for passthrough options (e.g. port in a Bun service), as well as the following specific options:

Adds appx. 45 bytes.

Considerations

The bulk of the bytes added is to support the explicit try/catch block (and rethrow). If we did not support errors in this, it would be closer to 460 bytes total (instead of 490).

Example Usage

import { Router, RouterType, error, json, withParams } from '../src/index'

const router = Router({
  port: 3000,
  after: json,
  error: error, // long form for clarity
})

router
  .get('/json', () => ({ foo: 'bar' }))
  .get('/throw', (a) => a.b.c) // this is caught!
  .all('*', () => error(404))

export default router

Type of Change (select one and follow subtasks)

kwhitley commented 3 months ago

I think this one will be killed in favor of AutoRouter. It makes sense to keep the core as minimalist as possible for use-cases that demand it, while allowing AutoRouter to be the batteries-included version for tiny demos.

kwhitley commented 3 months ago

Killed in favor of #222