docs: add middleware README documents (#145)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Yusuke Wada · committed by GitHub · parent 93b54e6 · Browse files · 6 files·+156 added−0 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+156 added−0 removed
- other:+156 added−0 removed
Provenance
- Commit
54e97ea- Tree
5b39046- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
93b54e6
6 files changed+156 added−0 removed
added:src/middleware/cors/README.md+30 added
123456789101112131415161718192021222324252627282930# CORS Middleware
## Usage
index.js:
```jsdescribe('CORS by Middleware', () => { 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.all('/api2/abc', (c) => { return c.json({ success: true }) })```added:src/middleware/etag/README.md+16 added
12345678910111213141516# ETag Middleware
## Usage
index.js:
```jsconst app = new Hono()
app.use('/etag/*', etag())app.get('/etag/abc', (c) => { return c.text('Hono is cool')})
app.fire()```added:src/middleware/graphql-server/README.md+47 added
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647# GraphQL Server Middleware
## Requirements
This middleware depends on [GraphQL.js](https://www.npmjs.com/package/graphql).
```plainnpm i graphql```
or
```plainyarn add graphql```
## Usage
index.js:
```jsimport { Hono } from 'hono'import { graphqlServer } from 'hono/graphql-server'import { buildSchema } from 'graphql'
export const app = new Hono()
const schema = buildSchema(`type Query { hello: String}`)
const rootValue = { hello: () => 'Hello Hono!',}
app.use( '/graphql', graphqlServer({ schema, rootValue, }))
app.fire()```added:src/middleware/logger/README.md+17 added
1234567891011121314151617# Logger Middleware
## Usage
index.js:
```jsimport { Hono } from 'hono'import { logger } from 'hono/logger'
export const app = new Hono()
app.use('*', logger())app.get('/', (c) => c.text('Hello Hono!'))
app.fire()```modified:src/middleware/mustache/README.md+4 added
63 unmodified lines646566676869707163 unmodified lines```mustache </body></html>```
## Example
<https://github.com/yusukebe/hono/tree/master/examples/mustache>added:src/middleware/serve-static/README.md+42 added
123456789101112131415161718192021222324252627282930313233343536373839404142# Serve Static Middleware
Mustache Middleware is available only on Cloudflare Workers.
## Usage
index.js:
```jsimport { Hono } from 'hono'import { serveStatic } from 'hono/serve-static'
const app = new Hono()
app.use('/static/*', serveStatic({ root: './' }))app.get('/', (c) => c.text('This is Home! You can access: /static/hello.txt'))
app.fire()```
wrangler.toml:
```toml[site]bucket = "./assets"```
Asset files:
```./assets└── static ├── demo │ └── index.html ├── hello.txt └── images └── dinotocat.png```
## Example
<https://github.com/yusukebe/hono/tree/master/examples/serve-static>