Fixed examples
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by Yusuke Wada · parent 3b339ec · Browse files · 5 files·+31 added−53 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+31 added−53 removed
- other:+31 added−53 removed
Provenance
- Commit
0ce2727- Tree
f45d2a4- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
3b339ec
5 files changed+31 added−53 removed
modified:example/basic/index.js-43 removed
24 unmodified lines252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707124 unmodified lines})
// addEventListenerapp.fire()
//
const logger = (c, next) => { console.log(`Req: [${c.req.method}] ${c.req.url}`) next() console.log(`Respond`)}
const auth = (c, next) => { const url = new URL(c.req.url) if (!url.pathname.match(/\/admin*/)) { next() } const auth = c.req.headers.get('x-auth') if (auth != 'auth-path') { return c.notFound() } next()}
const hello = (c, next) => { next() c.res.headers.append('x-message', 'Hello!')}
const notFound = (c, next) => { next() if (res.status === 404) { c.res = new Response('Not Found', { status: 404, }) }}
app.use('*', logger)app.use('*', notFound)app.use('/hello', hello)app.use('/admin/*', auth)
app.get('/admin', () => 'Your are Admin!')
const handler = app.matchRoute('GET', '/admin')added:src/middleware/defaultFilter.js+19 added
12345678910111213141516171819const defaultFilter = (c, next) => { c.req.query = (key) => { const url = new URL(c.req.url) return url.searchParams.get(key) }
next()
if (typeof c.res === 'string') { c.res = new Reponse(c.res, { status: 200, headers: { 'Conten-Type': 'text/plain', }, }) }}
module.exports = defaultFilterdeleted:src/middleware/filter.js-9 removed
123456789const filter = (c, next) => { c.req.query = (key) => { const url = new URL(c.req.url) return url.searchParams.get(key) } next()}
module.exports = filtermodified:src/hono.js+1 added-1 removed
1 'use strict'2 3 const Node = require('./node')4 const compose = require('./compose')5-const defaultFilter = require('./middleware/filter')5+const defaultFilter = require('./middleware/defaultFilter')6 7 class Router {8 constructor() {9 this.node = new Node()135 unmodified linesmodified:README.md+11 added
1 unmodified line2 3 Hono [炎] - Tiny web framework for Cloudflare Workers and others.4 5 ```js6+const Hono = require('Hono')7 const app = Hono()8 9 app.get('/', () => new Response('Hono!!'))10 7 unmodified lines18 - Portable - zero dependencies.19 - Flexible - you can make your own middlewares.20 - Optimized - for Cloudflare Workers and Fastly Compute@Edge.21 22+## Benchmark23+24+```25+hono x 813,001 ops/sec ±2.96% (75 runs sampled)26+itty-router x 160,415 ops/sec ±3.31% (85 runs sampled)27+sundar x 307,438 ops/sec ±4.77% (73 runs sampled)28+Fastest is hono29+✨ Done in 37.03s.30+```31+32 ## Install33 34 ```35 $ yarn add hono142 unmodified lines