tinyhttp / tinyhttp

🦄 0-legacy, tiny & fast web framework as a replacement of Express
https://tinyhttp.v1rtl.site
MIT License
2.72k stars 127 forks source link

[core] Add support for App as middleware #9

Closed talentlessguy closed 4 years ago

talentlessguy commented 4 years ago

Describe the solution you'd like

tinyhttp needs to have support of app.use(Router) and app.use(App) to be more compatible with express.

So we could do this:

import { App, Router } from '@tinyhttp/app'

const app = new App()

const router = new Router()

router.get('/', (req, res) => res.end('bruh'))

app.use('/sub-app',  router)

and this:

import { App } from '@tinyhttp/app'

const app = new App()

const subApp = new App()

subApp.get('/', (req, res) => res.end('bruh'))

app.use(subApp)

Additional context

Polka.js implementation: https://github.com/lukeed/polka/blob/88f380272973019df5dc7c37611ac987bcd67d47/packages/polka/index.js#L50-61

talentlessguy commented 4 years ago

Got partitially implemented in https://github.com/talentlessguy/tinyhttp/commit/ce2dd51e510b042e1e404238332ec136511fb39a

talentlessguy commented 4 years ago

not sure if Router also should be used as a ware, so closing it as it is implemented already