Skip to content
Myr

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

10 files+3 added−548 removed

deleted:src/middleware/basic-auth/README.md-47 removed
deleted:src/middleware/bearer-auth/README.md-34 removed
deleted:src/middleware/cors/README.md-29 removed
deleted:src/middleware/etag/README.md-16 removed
deleted:src/middleware/html/README.md-153 removed
1# html Middleware23html Middleware provides `html` method for building HTML.45## Usage67index.ts:89```ts10import { Hono } from 'hono'11import { html } from 'hono/html'1213const app = new Hono()1415app.get('/:username', (c) => {16 const { username } = c.req.param()17 return c.html(18 html`<!DOCTYPE html>19 <h1>Hello! ${username}!</h1>`20 )21})2223app.fire()24```2526### Insert snippet into JSX2728```typescript29const 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())3738 gtag('config', 'MEASUREMENT_ID')39 </script>40`4142app.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```5455### Insert inline script into JSX5657```typescript58app.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```7475### Act as functional component7677Since `html` returns an HtmlEscapedString, it can act as a fully functional component without using JSX.7879#### Use `html` to speed up the process instead of `memo`8081```typescript82const Footer = () => html`83 <footer>84 <address>My Address...</address>85 </footer>86`87```8889### Receives props and embeds values9091```typescript92interface SiteData {93 title: string94 description: string95 image: string96 children?: any97}98const 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`115116const Content = (props: { siteData: SiteData; name: string }) => (117 <Layout {...props.siteData}>118 <h1>Hello {props.name}</h1>119 </Layout>120)121122app.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```134135## raw136137Using `raw`, the content will be rendered as is. You have to escape these strings by yourself.138139```ts140import { html, raw } from 'hono/html'141142app.get('/', (c) => {143 const name = 'John &quot;Johnny&quot; Smith'144 return c.html(html`<p>I'm ${raw(name)}.</p>`)145})146```147148## Tips149150Thanks to these libraries, Visual Studio Code and vim also interprets template literals as HTML, allowing syntax highlighting and formatting to be applied.151152- <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 Middleware23JSX Middleware enable rendering HTML with JSX syntax.4It's just for Sever-Side-Rendering. No virtual DOM.5This middleware is only for writing with TypeScript.67## Settings89tsconfig.json:1011```json12{13 "compilerOptions": {14 "jsx": "react",15 "jsxFactory": "jsx",16 "jsxFragmentFactory": "Fragment"17 }18}19```2021## Usage2223index.tsx:2425```tsx26import { Hono } from 'hono'27import { jsx } from 'hono/jsx'2829const app = new Hono()3031const Layout = (props: { children?: string }) => {32 return (33 <html>34 <body>{props.children}</body>35 </html>36 )37}3839const 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}5152app.get('/', (c) => {53 const messages = ['Good Morning', 'Good Evening', 'Good Night']54 return c.html(<Top messages={messages} />)55})5657app.fire()58```5960## dangerouslySetInnerHTML6162`dangerouslySetInnerHTML` allows you to set HTML directly.6364```tsx65app.get('/foo', (c) => {66 const inner = { __html: 'JSX &middot; SSR' }67 const Div = <div dangerouslySetInnerHTML={inner} />68})69```7071## memo7273You can memorize calculated strings of the component with `memo`.7475```tsx76import { jsx, memo } from 'hono/jsx'7778const Header = memo(() => <header>Welcome to Hono</header>)79const Footer = memo(() => <footer>Powered by Hono</footer>)80const Layout = (81 <div>82 <Header />83 <p>Hono is cool!</p>84 <Footer />85 </div>86)87```8889## Fragment9091```tsx92import { jsx, Fragment } from 'hono/jsx'9394const List = () => (95 <Fragment>96 <p>first child</p>97 <p>second child</p>98 <p>third child</p>99 </Fragment>100)101```102103## With html Middleware104105It's powerful to use JSX middleware with html middleware.106For more information, see [html middleware docs](https://github.com/honojs/hono/tree/master/src/middleware/html).107108```tsx109import { Hono } from 'hono'110import { html } from 'hono/html'111import { jsx } from 'hono/jsx'112113const app = new Hono()114115interface SiteData {116 title: string117 children?: any118}119120const 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>`129130const Content = (props: { siteData: SiteData; name: string }) => (131 <Layout {...props.siteData}>132 <h1>Hello {props.name}</h1>133 </Layout>134)135136app.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})146147app.fire()148```149150## Tips for Cloudflare Workers151152It's useful to use Miniflare's`live-reload` option for developing.153154package.json:155156```json157{158 "scripts": {159 "build": "esbuild --bundle --outdir=dist ./src/index.tsx",160 "dev": "miniflare --live-reload --debug"161 }162}163```164165wrangler.toml:166167```toml168[build]169command = "yarn build"170```
deleted:src/middleware/jwt/README.md-23 removed
deleted:src/middleware/logger/README.md-17 removed
deleted:src/middleware/serve-static/README.md-56 removed
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>67<hr />
5 unmodified lines
1314<hr />1516[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/honojs/hono/ci)](https://github.com/honojs/hono/actions)17[![GitHub](https://img.shields.io/github/license/honojs/hono)](https://github.com/honojs/hono/blob/master/LICENSE)17[![GitHub](https://img.shields.io/github/license/honojs/hono)](https://github.com/honojs/hono/blob/main/LICENSE)18[![npm](https://img.shields.io/npm/v/hono)](https://www.npmjs.com/package/hono)19[![npm](https://img.shields.io/npm/dm/hono)](https://www.npmjs.com/package/hono)20[![npm type definitions](https://img.shields.io/npm/types/hono)](https://www.npmjs.com/package/hono)21[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/honojs/hono)](https://github.com/honojs/hono/pulse)22[![GitHub last commit](https://img.shields.io/github/last-commit/honojs/hono)](https://github.com/honojs/hono/commits/master)22[![GitHub last commit](https://img.shields.io/github/last-commit/honojs/hono)](https://github.com/honojs/hono/commits/main)23[![Deno badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fdeno-visualizer.danopia.net%2Fshields%2Flatest-version%2Fx%2Fhono%2Fmod.ts)](https://doc.deno.land/https/deno.land/x/hono/mod.ts)2425Hono - _**[炎] means flame🔥 in Japanese**_ - is a small, simple, and ultrafast web framework for Cloudflare Workers, Deno, Bun, and others.26
62 unmodified lines