docs: update readme
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 04460a6 · Browse files · 3 files·+119 added−35 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+119 added−35 removed
- other:+119 added−35 removed
Provenance
- Commit
b9745e7- Tree
6fde144- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
Yusuke Wada <yusuke@kamawada.com>- Parent
04460a6
3 files changed+119 added−35 removed
modified:docs/README.ja.md+58 added-5 removed
18 unmodified lines19 [](https://www.npmjs.com/package/hono)20 [](https://github.com/yusukebe/hono/pulse)21 [](https://github.com/yusukebe/hono/commits/master)22 23-Hono - _日本語の\[炎\]に由来 🔥_ - はCloudflare WorkersやFastly Compute@Edge向けの小さくて、シンプルで、めちゃくちゃ速いWebフレームワークです。23+Hono - _日本語の\[炎\]に由来 🔥_ - はCloudflare WorkersやFastly Compute@Edgeなど、Service Workerベースのサーバーレス向けの小さくて、シンプルで、めちゃくちゃ速いWebフレームワークです。24 25 ```js26 import { Hono } from 'hono'27 const app = new Hono()29 unmodified lines57 Honoを使って、Cloudflare Workersのアプリケーションを作っている様子です。58 59 60 61-名前付きパラメーターにも型がつきます。61+## 速いだけじゃない62 63+Honoは速いけど、速いだけではありません。64+65+### Write Less, do more66+67+ビルトイン・ミドルウェアが「**_Write Less, do more_**」を実現します。68+たくさんのミドルウェアを1からコードを書くことなく、使えます。69+例えば、以下のミドルウェアがあります。70+71+- [Basic認証](https://github.com/yusukebe/hono/tree/master/src/middleware/basic-auth/)72+- [Cookieパース/シリアライゼーション](https://github.com/yusukebe/hono/tree/master/src/middleware/cookie/)73+- [CORS](https://github.com/yusukebe/hono/tree/master/src/middleware/cors/)74+- [ETag](https://github.com/yusukebe/hono/tree/master/src/middleware/etag/)75+- [GraphQLサーバー](https://github.com/yusukebe/hono/tree/master/src/middleware/graphql-server/)76+- [ロガー](https://github.com/yusukebe/hono/tree/master/src/middleware/logger/)77+- [Mustacheを使ったテンプレート](https://github.com/yusukebe/hono/tree/master/src/middleware/mustache/) (Cloudflare Workersのみ)78+- [JSON pretty](https://github.com/yusukebe/hono/tree/master/src/middleware/pretty-json/)79+- [静的ファイルのサーブ](https://github.com/yusukebe/hono/tree/master/src/middleware/serve-static/) (Cloudflare Workersのみ)80+81+たったこれだけのコードでロガーとCORSミドルウェアを使うことができます。82+83+```js84+import { Hono } from 'hono'85+import { cors } from 'hono/cors'86+import { logger } from 'hono/logger'87+88+const app = new Hono()89+app.use('*', cors()).use(logger())90+```91+92+### Developer Experience93+94+そして、Honoは優れた「**_Developer Experience_**」を提供します。`Context` オブジェクトのおかげで、Request/Responseへのアクセスが簡単です。なにより、HonoはTypeScriptで書かれています。そう、Honoは「**_型_**」を持っているのです!95+96+例えば、名前付きパラメーターにもリテラル型がつきます。97+98 99 100 ## インストール101 12 unmodified lines114 ## メソッド115 116 `Hono`のインスタンスには以下のメソッドがあります。117 83-- app.**HTTP_METHOD**(path, handler)84-- app.**all**(path, handler)118+- app.**HTTP_METHOD**(\[path,\] handler)119+- app.**all**(\[path,\] handler)120 - app.**route**(path)86-- app.**use**(path, middleware)121+- app.**use**(\[path,\] middleware)122 - app.**notFound**(handler)123 - app.**onError**(err, handler)124 - app.**fire**()125 - app.**fetch**(request, env, event)35 unmodified lines161 ...162 })163 ```164 165+### チェインされたルート166+167+```js168+app169+ .get('/endpoint', (c) => {170+ return c.text('GET /endpoint')171+ })172+ .post((c) => {173+ return c.text('POST /endpoint')174+ })175+ .delete((c) => {176+ return c.text('DELETE /endpoint')177+ })178+```179+180 ### ネストされたルート181 182 ```js183 const book = app.route('/book')40 unmodified lines224 const app = new Hono()225 226 app.use('*', poweredBy())227 app.use('*', logger())228+// もしくはこのようにも書けます。229+// app.use('*', poweredBy()).use(logger())230+231 app.use(232 '/auth/*',233 basicAuth({234 username: 'hono',356 unmodified linesmodified:src/middleware/cors/README.md+19 added-20 removed
3 unmodified lines4567898911121314151617181920212223242510111213141516171819202122232425272829262728293 unmodified lines
index.js:
```jsdescribe('CORS by Middleware', () => { const app = new Hono()const app = new Hono()
app.use('/api/*', cors()) app.use( '/api2/*', cors({ origin: 'http://example.com', allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'], allowMethods: ['POST', 'GET', 'OPTIONS'], exposeHeaders: ['Content-Length', 'X-Kuma-Revision'], maxAge: 600, credentials: true, }) )
app.all('/api/abc', (c) => { return c.json({ success: true })app.use('/api/*', cors())app.use( '/api2/*', cors({ origin: 'http://example.com', allowHeaders: ['X-Custom-Header', 'Upgrade-Insecure-Requests'], allowMethods: ['POST', 'GET', 'OPTIONS'], exposeHeaders: ['Content-Length', 'X-Kuma-Revision'], maxAge: 600, credentials: true, }))
app.all('/api/abc', (c) => { return c.json({ success: true })}) app.all('/api2/abc', (c) => { return c.json({ success: true }) })app.all('/api2/abc', (c) => { return c.json({ success: true })})```modified:README.md+42 added-10 removed
18 unmodified lines19 [](https://www.npmjs.com/package/hono)20 [](https://github.com/yusukebe/hono/pulse)21 [](https://github.com/yusukebe/hono/commits/master)22 23-Hono - _**[炎] means flame🔥 in Japanese**_ - is small, simple, and ultrafast web framework for Cloudflare Workers and Fastly Compute@Edge.23+Hono - _**[炎] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for Cloudflare Workers and Service Worker based serverless such as Fastly Compute@Edge.24 25 ```js26 import { Hono } from 'hono'27 const app = new Hono()8 unmodified lines36 - **Ultrafast** - the router does not use linear loops.37 - **Zero-dependencies** - using only Service Worker and Web standard API.38 - **Middleware** - built-in middleware and ability to extend with your own middleware.39 - **TypeScript** - first-class TypeScript support.40-- **Optimized** - for Cloudflare Workers.40+- **Optimized** - for Cloudflare Workers and Fastly Compute@Edge.41 42 ## Benchmark43 44 **Hono is fastest**, compared to other routers for Cloudflare Workers.12 unmodified lines57 A demonstration to create an application for Cloudflare Workers with Hono.58 59 60 61-Now, the named path parameter has types.61+## Not only fast62 63+Hono is fast. But not only fast.64+65+### Write Less, do more66+67+Built-in middleware make _"**Write Less, do more**"_ in reality. You can use a lot of middleware without writing code from scratch. Below are examples.68+69+- [Basic Authentication](https://github.com/yusukebe/hono/tree/master/src/middleware/basic-auth/)70+- [Cookie parsing / serializing](https://github.com/yusukebe/hono/tree/master/src/middleware/cookie/)71+- [CORS](https://github.com/yusukebe/hono/tree/master/src/middleware/cors/)72+- [ETag](https://github.com/yusukebe/hono/tree/master/src/middleware/etag/)73+- [GraphQL Server](https://github.com/yusukebe/hono/tree/master/src/middleware/graphql-server/)74+- [Logger](https://github.com/yusukebe/hono/tree/master/src/middleware/logger/)75+- [Mustache template engine](https://github.com/yusukebe/hono/tree/master/src/middleware/mustache/) (Only for Cloudflare Workers)76+- [JSON pretty printing](https://github.com/yusukebe/hono/tree/master/src/middleware/pretty-json/)77+- [Serving static files](https://github.com/yusukebe/hono/tree/master/src/middleware/serve-static/) (Only for Cloudflare Workers)78+79+You can enable logger and CORS middleware with just this code.80+81+```js82+import { Hono } from 'hono'83+import { cors } from 'hono/cors'84+import { logger } from 'hono/logger'85+86+const app = new Hono()87+app.use('*', cors()).use(logger())88+```89+90+### Developer Experience91+92+And Hono provides fine _"**Developer Experience**"_. Easy access to Request/Response thanks to the `Context` object.93+Above all, Hono is written in TypeScript. So, Hono has _"**Types**"_!94+95+For example, the named path parameters will be literal types.96+97 98 99 ## Install100 12 unmodified lines113 ## Methods114 115 An instance of `Hono` has these methods.116 83-- app.**HTTP_METHOD**(path, handler)84-- app.**all**(path, handler)117+- app.**HTTP_METHOD**(\[path,\] handler)118+- app.**all**(\[path,\] handler)119 - app.**route**(path)86-- app.**use**(path, middleware)120+- app.**use**(\[path,\] middleware)121 - app.**notFound**(handler)122 - app.**onError**(err, handler)123 - app.**fire**()124 - app.**fetch**(request, env, event)415 unmodified lines540 ```541 542 ## Starter template543 510-You can start making your Cloudflare Workers application with [the starter template](https://github.com/yusukebe/hono-minimal). It is really minimal using TypeScript, esbuild, and Miniflare.544+You can start making your Cloudflare Workers application with [the starter template](https://github.com/yusukebe/hono-minimal). It is really minimal using TypeScript, esbuild, Miniflare, and Jest.545 546 To generate a project skelton, run this command.547 548 ```sh13 unmodified lines562 - Router::Boom <https://github.com/tokuhirom/Router-Boom>563 564 ## Contributing565 532-Contributions Welcome! You can contribute by the following way.566+Contributions Welcome! You can contribute in the following ways.567 568 - Write or fix documents569 - Write code of middleware570 - Fix bugs571 - Refactor the code572 - etc.573 540-Let's make Hono together!541-574 ## Contributors575 576 Thanks to [all contributors](https://github.com/yusukebe/hono/graphs/contributors)!577 7 unmodified lines