docs: rename `master` to `main` and remove README from middlewre directories (#405)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* chore: add conf file to categorize the PRs on release note Inspired by https://github.com/r7kamura/github-label-presets * docs: rename `master` to `main` and remove README from middlewre directories If you want read the document about the middleware, please refer to the website <https://honojs.dev/>
authored by Yusuke Wada · committed by GitHub · parent bcc9818 · Browse files · 10 files·+3 added−548 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+3 added−548 removed
- other:+3 added−548 removed
Provenance
- Commit
7738c99- Tree
cac88b2- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
bcc9818
10 files changed+3 added−548 removed
deleted:src/middleware/basic-auth/README.md-47 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647# Basic Auth Middleware
## Usage
```jsimport { Hono } from 'hono'import { basicAuth } from 'hono/basic-auth'
const app = new Hono()
app.use( '/auth/*', basicAuth({ username: 'hono', password: 'acoolproject', }))
app.get('/auth/page', (c) => { return c.text('You are authorized')})
app.fire()```
For Fastly Compute@Edge, polyfill `crypto` or use `crypto-js`.
Install:
```npm i crypto-js```
Override `hashFunction`:
```jsimport { SHA256 } from 'crypto-js'
app.use( '/auth/*', basicAuth({ username: 'hono', password: 'acoolproject', hashFunction: (d: string) => SHA256(d).toString(), // <--- }))```deleted:src/middleware/bearer-auth/README.md-34 removed
12345678910111213141516171819202122232425262728293031323334# Bearer Auth Middleware
## Usage
```tsimport { Hono } from 'hono'import { bearerAuth } from 'hono/bearer-auth'
const app = new Hono()
const token = 'honoisacool'
app.use('/auth/*', bearerAuth({ token }))
app.get('/auth/page', (c) => { return c.text('You are authorized')})
app.fire()```
## Options
```tsapp.use( '/auth/*', bearerAuth({ token: 'honoisacool', // Required realm: 'example.com', prefix: 'Bot' hashFunction: (d: string) => SHA256(d).toString(), // For Fastly Compute@Edge }))```deleted:src/middleware/cors/README.md-29 removed
1234567891011121314151617181920212223242526272829# CORS Middleware
## Usage
index.js:
```jsconst 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 })})```deleted:src/middleware/etag/README.md-16 removed
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()```deleted:src/middleware/html/README.md-153 removed
1-# html Middleware2-3-html Middleware provides `html` method for building HTML.4-5-## Usage6-7-index.ts:8-9-```ts10-import { Hono } from 'hono'11-import { html } from 'hono/html'12-13-const app = new Hono()14-15-app.get('/:username', (c) => {16- const { username } = c.req.param()17- return c.html(18- html`<!DOCTYPE html>19- <h1>Hello! ${username}!</h1>`20- )21-})22-23-app.fire()24-```25-26-### Insert snippet into JSX27-28-```typescript29-const snippet = html`30- <script async src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"></script>31- <script>32- window.dataLayer = window.dataLayer || []33- function gtag() {34- dataLayer.push(arguments)35- }36- gtag('js', new Date())37-38- gtag('config', 'MEASUREMENT_ID')39- </script>40-`41-42-app.get('/', (c) => {43- return c.render(44- <html>45- <head>46- <title>Test Site</title>47- {snippet}48- </head>49- <body>Hello!</body>50- </html>51- )52-})53-```54-55-### Insert inline script into JSX56-57-```typescript58-app.get('/', (c) => {59- return c.render(60- <html>61- <head>62- <title>Test Site</title>63- {html`64- <script>65- // No need to use dangerouslySetInnerHTML. If you write it here, it will not be escaped.66- </script>67- `}68- </head>69- <body>Hello!</body>70- </html>71- )72-})73-```74-75-### Act as functional component76-77-Since `html` returns an HtmlEscapedString, it can act as a fully functional component without using JSX.78-79-#### Use `html` to speed up the process instead of `memo`80-81-```typescript82-const Footer = () => html`83- <footer>84- <address>My Address...</address>85- </footer>86-`87-```88-89-### Receives props and embeds values90-91-```typescript92-interface SiteData {93- title: string94- description: string95- image: string96- children?: any97-}98-const Layout = (props: SiteData) => html`99-<html>100-<head>101- <meta charset="UTF-8">102- <title>${props.title}</title>103- <meta name="description" content="${props.description}">104- <head prefix="og: http://ogp.me/ns#">105- <meta property="og:type" content="article">106- <!-- More elements slow down JSX, but not template literals. -->107- <meta property="og:title" content="${props.title}">108- <meta property="og:image" content="${props.image}">109-</head>110-<body>111- ${props.children}112-</body>113-</html>114-`115-116-const Content = (props: { siteData: SiteData; name: string }) => (117- <Layout {...props.siteData}>118- <h1>Hello {props.name}</h1>119- </Layout>120-)121-122-app.get('/', (c) => {123- const props = {124- name: 'World',125- siteData: {126- title: 'Hello <> World',127- description: 'This is a description',128- image: 'https://example.com/image.png',129- },130- }131- return c.render(<Content {...props} />)132-})133-```134-135-## raw136-137-Using `raw`, the content will be rendered as is. You have to escape these strings by yourself.138-139-```ts140-import { html, raw } from 'hono/html'141-142-app.get('/', (c) => {143- const name = 'John "Johnny" Smith'144- return c.html(html`<p>I'm ${raw(name)}.</p>`)145-})146-```147-148-## Tips149-150-Thanks to these libraries, Visual Studio Code and vim also interprets template literals as HTML, allowing syntax highlighting and formatting to be applied.151-152-- <https://marketplace.visualstudio.com/items?itemName=bierner.lit-html>153-- <https://github.com/MaxMEllon/vim-jsx-pretty>deleted:src/middleware/jsx/README.md-170 removed
1-# JSX Middleware2-3-JSX Middleware enable rendering HTML with JSX syntax.4-It's just for Sever-Side-Rendering. No virtual DOM.5-This middleware is only for writing with TypeScript.6-7-## Settings8-9-tsconfig.json:10-11-```json12-{13- "compilerOptions": {14- "jsx": "react",15- "jsxFactory": "jsx",16- "jsxFragmentFactory": "Fragment"17- }18-}19-```20-21-## Usage22-23-index.tsx:24-25-```tsx26-import { Hono } from 'hono'27-import { jsx } from 'hono/jsx'28-29-const app = new Hono()30-31-const Layout = (props: { children?: string }) => {32- return (33- <html>34- <body>{props.children}</body>35- </html>36- )37-}38-39-const Top = (props: { messages: string[] }) => {40- return (41- <Layout>42- <h1>Hello Hono!</h1>43- <ul>44- {props.messages.map((message) => {45- return <li>{message}!!</li>46- })}47- </ul>48- </Layout>49- )50-}51-52-app.get('/', (c) => {53- const messages = ['Good Morning', 'Good Evening', 'Good Night']54- return c.html(<Top messages={messages} />)55-})56-57-app.fire()58-```59-60-## dangerouslySetInnerHTML61-62-`dangerouslySetInnerHTML` allows you to set HTML directly.63-64-```tsx65-app.get('/foo', (c) => {66- const inner = { __html: 'JSX · SSR' }67- const Div = <div dangerouslySetInnerHTML={inner} />68-})69-```70-71-## memo72-73-You can memorize calculated strings of the component with `memo`.74-75-```tsx76-import { jsx, memo } from 'hono/jsx'77-78-const Header = memo(() => <header>Welcome to Hono</header>)79-const Footer = memo(() => <footer>Powered by Hono</footer>)80-const Layout = (81- <div>82- <Header />83- <p>Hono is cool!</p>84- <Footer />85- </div>86-)87-```88-89-## Fragment90-91-```tsx92-import { jsx, Fragment } from 'hono/jsx'93-94-const List = () => (95- <Fragment>96- <p>first child</p>97- <p>second child</p>98- <p>third child</p>99- </Fragment>100-)101-```102-103-## With html Middleware104-105-It's powerful to use JSX middleware with html middleware.106-For more information, see [html middleware docs](https://github.com/honojs/hono/tree/master/src/middleware/html).107-108-```tsx109-import { Hono } from 'hono'110-import { html } from 'hono/html'111-import { jsx } from 'hono/jsx'112-113-const app = new Hono()114-115-interface SiteData {116- title: string117- children?: any118-}119-120-const Layout = (props: SiteData) => html`<!DOCTYPE html>121- <html>122- <head>123- <title>${props.title}</title>124- </head>125- <body>126- ${props.children}127- </body>128- </html>`129-130-const Content = (props: { siteData: SiteData; name: string }) => (131- <Layout {...props.siteData}>132- <h1>Hello {props.name}</h1>133- </Layout>134-)135-136-app.get('/:name', (c) => {137- const { name } = c.req.param()138- const props = {139- name: name,140- siteData: {141- title: 'JSX with html sample',142- },143- }144- return c.html(<Content {...props} />)145-})146-147-app.fire()148-```149-150-## Tips for Cloudflare Workers151-152-It's useful to use Miniflare's`live-reload` option for developing.153-154-package.json:155-156-```json157-{158- "scripts": {159- "build": "esbuild --bundle --outdir=dist ./src/index.tsx",160- "dev": "miniflare --live-reload --debug"161- }162-}163-```164-165-wrangler.toml:166-167-```toml168-[build]169-command = "yarn build"170-```deleted:src/middleware/jwt/README.md-23 removed
1234567891011121314151617181920212223# JWT Middleware
## Usage
```jsimport { Hono } from 'hono'import { jwt } from 'hono/jwt'
const app = new Hono()
app.use( '/auth/*', jwt({ secret: 'it-is-very-secret' }))
app.get('/auth/page', (c) => { return c.text('You are authorized')})
app.fire()```deleted:src/middleware/logger/README.md-17 removed
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()```deleted:src/middleware/serve-static/README.md-56 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556# Serve Static Middleware
Serve Static Middleware is available only on Cloudflare Workers.
## Usage
index.ts:
```tsimport { 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.get('*', serveStatic({ path: './static/fallback.txt' }))
app.fire()```
In Module Worker mode:
```tsimport { Hono } from 'hono'import { serveStatic } from 'hono/serve-static.module' // <---
const app = new Hono()//...
export default app```
wrangler.toml:
```toml[site]bucket = "./assets"```
Asset files:
```./assets└── static ├── demo │ └── index.html ├── hello.txt ├── fallback.txt └── images └── dinotocat.png```
## Example
<https://github.com/honojs/examples/tree/master/serve-static>modified:README.md+3 added-3 removed
1 <div align="center">2 <a href="https://honojs.dev">3- <img src="https://raw.githubusercontent.com/honojs/hono/master/docs/images/hono-title.png" width="500" height="auto" alt="Hono"/>3+ <img src="https://raw.githubusercontent.com/honojs/hono/main/docs/images/hono-title.png" width="500" height="auto" alt="Hono"/>4 </a>5 </div>6 7 <hr />5 unmodified lines13 14 <hr />15 16 [](https://github.com/honojs/hono/actions)17-[](https://github.com/honojs/hono/blob/master/LICENSE)17+[](https://github.com/honojs/hono/blob/main/LICENSE)18 [](https://www.npmjs.com/package/hono)19 [](https://www.npmjs.com/package/hono)20 [](https://www.npmjs.com/package/hono)21 [](https://github.com/honojs/hono/pulse)22-[](https://github.com/honojs/hono/commits/master)22+[](https://github.com/honojs/hono/commits/main)23 [](https://doc.deno.land/https/deno.land/x/hono/mod.ts)24 25 Hono - _**[炎] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for Cloudflare Workers, Deno, Bun, and others.26 62 unmodified lines