Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 6 commits into from

Conversation

kwhitley
Copy link
Owner

@kwhitley kwhitley commented Jan 8, 2024

Description

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

  • after: what you would pass to a .then() chain on the router.handle/router.fetch.
  • errors: what you would pass to a catch block. if not defined, Router will still throw (uncaught).

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)

  • Documentation (README.md)
  • Maintenance or repo-level work (e.g. linting, build, tests, refactoring, etc.)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
    • I have included test coverage
  • Breaking change (fix or feature that would cause existing functionality/userland code to not work as expected)
    • Explain why a breaking change is necessary:
  • This change requires (or is) a documentation update
    • I have added necessary local documentation (if appropriate)
    • I have added necessary itty.dev documentation (if appropriate)

@kwhitley kwhitley added new feature New feature or request discussion Let's discuss in progress I'm working on it... allegedly... labels Jan 8, 2024
@kwhitley kwhitley changed the title Draft: adds flow options to basic Router, as well as custom option/object passthrough DRAFT: adds flow options to basic Router, as well as custom option/object passthrough Jan 8, 2024
@kwhitley
Copy link
Owner Author

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 kwhitley added ON HOLD and removed in progress I'm working on it... allegedly... labels Mar 12, 2024
@kwhitley
Copy link
Owner Author

Killed in favor of #222

@kwhitley kwhitley closed this Mar 15, 2024
@kwhitley kwhitley deleted the format-option branch March 24, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Let's discuss new feature New feature or request ON HOLD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant