chore: move examples to github.com/honojs/examples (#181)
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 feebd88 · Browse files · 52 files·+2 added−1030 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
52 files+2 added−1030 removed
- tests:+0 added−79 removed
- other:+2 added−951 removed
Provenance
- Commit
13373f0- Tree
8d749a5- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
feebd88
52 files changed+2 added−1030 removed
deleted:examples/basic/.gitignore-5 removed
1-dist2-node_modules3-worker4-package-lock.json5-yarn.lockdeleted:examples/basic/index.js-115 removed
1-import { Hono } from 'hono'2-import { basicAuth } from 'hono/basic-auth'3-import { bodyParse } from 'hono/body-parse'4-import { etag } from 'hono/etag'5-import { logger } from 'hono/logger'6-import { poweredBy } from 'hono/powered-by'7-8-const app = new Hono()9-10-// Mount Builtin Middleware11-app.use('*', poweredBy())12-app.use('*', logger())13-app.use('/form', bodyParse())14-app.use(15- '/auth/*',16- basicAuth({17- username: 'hono',18- password: 'acoolproject',19- })20-)21-app.use('/etag/*', etag())22-23-// Custom Middleware24-// Add Custom Header25-app.use('/hello/*', async (c, next) => {26- await next()27- c.header('X-message', 'This is addHeader middleware!')28-})29-30-// Add X-Response-Time header31-app.use('*', async (c, next) => {32- const start = Date.now()33- await next()34- const ms = Date.now() - start35- c.header('X-Response-Time', `${ms}ms`)36-})37-38-// Custom Not Found Message39-app.notFound((c) => {40- return c.text('Custom 404 Not Found', 404)41-})42-43-// Error handling44-app.onError((err, c) => {45- console.error(`${err}`)46- return c.text('Custom Error Message', 500)47-})48-49-// Routing50-app.get('/', (c) => c.text('Hono!!'))51-// Use Response object directly52-app.get('/hello', () => new Response('This is /hello'))53-54-// Named parameter55-app.get('/entry/:id', (c) => {56- const id = c.req.param('id')57- return c.text(`Your ID is ${id}`)58-})59-60-// Nested route61-const book = app.route('/book')62-book.get('/', (c) => c.text('List Books'))63-book.get('/:id', (c) => {64- const id = c.req.param('id')65- return c.text('Get Book: ' + id)66-})67-book.post('/', (c) => c.text('Create Book'))68-69-// Redirect70-app.get('/redirect', (c) => c.redirect('/'))71-// Authentication required72-app.get('/auth/*', (c) => c.text('You are authorized'))73-// ETag74-app.get('/etag/cached', (c) => c.text('Is this cached?'))75-76-// Async77-app.get('/fetch-url', async (c) => {78- const response = await fetch('https://example.com/')79- return c.text(`https://example.com/ is ${response.status}`)80-})81-82-// Request headers83-app.get('/user-agent', (c) => {84- const userAgent = c.req.header('User-Agent')85- return c.text(`Your UserAgent is ${userAgent}`)86-})87-88-// JSON89-app.get('/api/posts', (c) => {90- const posts = [91- { id: 1, title: 'Good Morning' },92- { id: 2, title: 'Good Aternoon' },93- { id: 3, title: 'Good Evening' },94- { id: 4, title: 'Good Night' },95- ]96- return c.json(posts)97-})98-// status code99-app.post('/api/posts', (c) => c.json({ message: 'Created!' }, 201))100-// default route101-app.get('/api/*', (c) => c.text('API endpoint is not found', 404))102-103-app.post('/form', async (c) => {104- return c.json(c.req.parsedBody || {})105- //return new Response('ok /form')106-})107-108-// Throw Error109-app.get('/error', () => {110- throw Error('Error has occurred')111-})112-app.get('/type-error', () => 'return not Response instance')113-114-// addEventListener115-app.fire()deleted:examples/basic/package.json-19 removed
12345678910111213141516171819{ "name": "hono-example-basic", "version": "0.0.1", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "wrangler dev index.js", "deploy": "wrangler publish index.js" }, "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)", "license": "MIT", "dependencies": { "hono": "^0.5.10" }, "devDependencies": { "wrangler": "^0.0.26" }}No newline at end of filedeleted:examples/basic/README.md-11 removed
1234567891011# Hono example for Cloudflare Workers
Before you can start publishing your service to cloudflare worker, you must sign up for a Cloudflare Workers account first, you can check out this [document](https://developers.cloudflare.com/workers/get-started/guide)
You can update the information (`name`, `zoon_id`, etc) in wrangler file, then you can test and deploy your service by simply doing,
```sh$ npm install$ npm run dev # Start a local server for developing your worker$ npm run deploy # Publish your worker to the orange cloud```deleted:examples/basic/wrangler.toml-3 removed
123name = "hono-example-basic"workers_dev = truecompatibility_date = "2021-12-15"deleted:examples/blog/src/controller.ts-53 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import type { Context } from 'hono'import * as Model from './model'
export const root = (c: Context) => { return c.json({ message: 'Hello' })}
export const list = async (c: Context) => { const posts = await Model.getPosts() return c.json({ posts: posts, ok: true })}
export const create = async (c: Context) => { let newPost: Model.Post | undefined if (c.req.parsedBody) { const param: Model.Param = c.req.parsedBody newPost = await Model.createPost(param) } if (!newPost) { return c.json({ error: 'Can not create new post', ok: false }, 422) } return c.json({ post: newPost, ok: true }, 201)}
export const show = async (c: Context<'id'>) => { const id = c.req.param('id') const post = await Model.getPost(id) if (!post) { return c.json({ error: 'Not Found', ok: false }, 404) } return c.json({ post: post, ok: true })}
export const update = async (c: Context<'id'>) => { const id = c.req.param('id') if (!(await Model.getPost(id))) { // 204 No Content return c.json({ ok: false }, 204) } const param = c.req.parsedBody as Model.Param const success = await Model.updatePost(id, param) return c.json({ ok: success })}
export const destroy = async (c: Context<'id'>) => { const id = c.req.param('id') if (!(await Model.getPost(id))) { // 204 No Content return c.json({ ok: false }, 204) } const success = await Model.deletePost(id) return c.json({ ok: success })}deleted:examples/blog/src/index.test.ts-79 removed
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879import type { Post } from './model'import { app } from './index'
describe('Root', () => { it('GET /', async () => { const res = await app.request('http://localhost/') expect(res.status).toBe(200) const body = await res.json() expect(body['message']).toBe('Hello') })})
describe('Blog API', () => { it('List', async () => { const res = await app.request('http://localhost/posts') expect(res.status).toBe(200) const body = await res.json() expect(body['posts']).not.toBeUndefined() expect(body['posts'].length).toBe(0) })
it('CRUD', async () => { let payload = JSON.stringify({ title: 'Morning', body: 'Good Morning' }) let req = new Request('http://localhost/posts', { method: 'POST', body: payload, headers: { 'Content-Type': 'application/json' }, }) let res = await app.request(req) expect(res.status).toBe(201) let body = await res.json() const newPost = body['post'] as Post expect(newPost.title).toBe('Morning') expect(newPost.body).toBe('Good Morning')
res = await app.request('https://localhost/posts') expect(res.status).toBe(200) body = await res.json() expect(body['posts']).not.toBeUndefined() expect(body['posts'].length).toBe(1)
res = await app.request(`https://localhost/posts/${newPost.id}`) expect(res.status).toBe(200) body = await res.json() let post = body['post'] as Post expect(post.id).toBe(newPost.id) expect(post.title).toBe('Morning') const postId = post.id
payload = JSON.stringify({ title: 'Night', body: 'Good Night' }) req = new Request(`https://localhost/posts/${postId}`, { method: 'PUT', body: payload, headers: { 'Content-Type': 'application/json' }, }) res = await app.request(req) expect(res.status).toBe(200) body = await res.json() expect(body['ok']).toBeTruthy()
res = await app.request(`https://localhost/posts/${postId}`) expect(res.status).toBe(200) body = await res.json() post = body['post'] as Post expect(post.title).toBe('Night') expect(post.body).toBe('Good Night')
req = new Request(`https://localhost/posts/${postId}`, { method: 'DELETE', }) res = await app.request(req) expect(res.status).toBe(200) body = await res.json() expect(body['ok']).toBeTruthy()
res = await app.request(`https://localhost/posts/${postId}`) expect(res.status).toBe(404) })})deleted:examples/blog/src/index.ts-21 removed
123456789101112131415161718192021import { Hono } from 'hono'
import { bodyParse } from 'hono/body-parse'import { cors } from 'hono/cors'
import * as Controller from './controller'
export const app = new Hono()
app.use('/posts/*', bodyParse())app.use('/posts/*', cors())
app.get('/', Controller.root)
app.get('/posts', Controller.list)app.post('/posts', Controller.create)app.get('/posts/:id', Controller.show)app.put('/posts/:id', Controller.update)app.delete('/posts/:id', Controller.destroy)
app.fire()deleted:examples/blog/src/model.ts-71 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071declare const BLOG_EXAMPLE: KVNamespaceconst PREFIX = 'v1:post:'
declare global { interface Crypto { randomUUID(): string }}
export interface Post { id: string title: string body: string}
export type Param = { title: string body: string}
const generateID = (key: string) => { return `${PREFIX}${key}`}
export const getPosts = async (): Promise<Post[]> => { const list = await BLOG_EXAMPLE.list({ prefix: PREFIX }) const keys = list.keys
const posts: Post[] = []
for (const key of keys) { const value = await BLOG_EXAMPLE.get(key.name) if (!value) continue const post: Post = JSON.parse(value) posts.push(post) }
return posts}
export const getPost = async (id: string): Promise<Post | undefined> => { const value = await BLOG_EXAMPLE.get(generateID(id)) if (!value) return const post: Post = JSON.parse(value) return post}
export const createPost = async (param: Param): Promise<Post | undefined> => { if (!(param.title && param.body)) return const id = crypto.randomUUID() const newPost: Post = { id: id, title: param.title, body: param.body } await BLOG_EXAMPLE.put(generateID(id), JSON.stringify(newPost)) return newPost}
export const updatePost = async (id: string, param: Param): Promise<boolean> => { if (!(param.title && param.body)) return false const post = await getPost(id) if (!post) return false post.title = param.title post.body = param.body await BLOG_EXAMPLE.put(generateID(id), JSON.stringify(post)) return true}
export const deletePost = async (id: string): Promise<boolean> => { const post = await getPost(id) if (!post) return false await BLOG_EXAMPLE.delete(generateID(id)) return true}deleted:examples/blog/.gitignore-6 removed
1-dist2-node_modules3-worker4-package-lock.json5-yarn.lock6-wrangler.tomldeleted:examples/blog/jest.config.js-8 removed
1-module.exports = {2- testEnvironment: 'miniflare',3- testMatch: ['**/test/**/*.+(ts|tsx|js)', '**/src/**/(*.)+(spec|test).+(ts|tsx|js)'],4- transform: {5- '^.+\\.(ts|tsx)$': 'esbuild-jest',6- },7- resolver: 'jest-node-exports-resolver',8-}deleted:examples/blog/package.json-26 removed
1-{2- "name": "hono-example-blog",3- "version": "0.0.1",4- "description": "",5- "main": "dist/index.js",6- "scripts": {7- "build": "esbuild --bundle --outdir=dist ./src/index.ts",8- "dev": "miniflare --live-reload --debug",9- "deploy": "wrangler publish dist/index.js",10- "test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose"11- },12- "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)",13- "license": "MIT",14- "dependencies": {15- "hono": "^0.5.4"16- },17- "devDependencies": {18- "@cloudflare/workers-types": "^3.3.1",19- "esbuild": "^0.14.21",20- "esbuild-jest": "^0.5.0",21- "jest": "^27.5.0",22- "jest-environment-miniflare": "^2.2.0",23- "jest-node-exports-resolver": "^1.1.5",24- "miniflare": "^2.3.0"25- }26-}deleted:examples/blog/README.md-75 removed
1-# hono-example-blog2-3-CRUD web API for Blog.4-5-## Features6-7-- Cloudflare Workers8-- KV9-- TypeScript10-- `esbuild` for build11-- `miniflare` for development12-- `wrangler@beta` for deploy13-- Test with Jest `miniflare environment`14-15-## Endpoints16-17-- `GET /posts`18-- `POST /posts`19-- `GET /posts/:id`20-- `PUT /posts/:id`21-- `DELETE /posts/:id`22-23-## Usage24-25-Install dependencies:26-27-```sh28-$ yarn run install29-```30-31-Rename `wrangler.example.toml` to `wrangler.toml`:32-33-```sh34-$ mv wrangler.example.toml wrangler.toml35-```36-37-Setup KV:38-39-```sh40-$ wrangler kv:namespace create BLOG_EXAMPLE --preview41-42-🌀 Creating namespace with title "hono-example-blog-BLOG_EXAMPLE_preview"43-✨ Success!44-Add the following to your configuration file in your kv_namespaces array:45-{ binding = "BLOG_EXAMPLE", preview_id = "xxxxxxxxxx" }46-```47-48-```sh49-$ wrangler kv:namespace create BLOG_EXAMPLE50-51-🌀 Creating namespace with title "hono-example-blog-BLOG_EXAMPLE"52-✨ Success!53-Add the following to your configuration file in your kv_namespaces array:54-{ binding = "BLOG_EXAMPLE", id = "yyyyyyyyyy" }55-```56-57-Copy KV id:58-59-```toml60-kv_namespaces = [61- { binding = "BLOG_EXAMPLE", preview_id = "xxxxxxxxxx", id = "yyyyyyyyy" }62-]63-```64-65-Run a development server:66-67-```sh68-$ yarn dev69-```70-71-Publish:72-73-```sh74-$ yarn deploy75-```deleted:examples/blog/wrangler.example.toml-15 removed
1-name = "hono-example-blog"2-type = "javascript"3-workers_dev = true4-5-compatibility_date = "2022-02-03"6-7-kv_namespaces = [8- { binding = "BLOG_EXAMPLE", preview_id = "", id = "" }9-]10-11-[build]12-command = "yarn run build"13-14-[build.upload]15-format = "service-worker"deleted:examples/compute-at-edge/src/index.ts-22 removed
1-import { SHA256 } from 'crypto-js'2-import { Hono } from 'hono'3-import { basicAuth } from 'hono/basic-auth'4-5-const app = new Hono()6-7-app.use(8- '/auth/*',9- basicAuth({10- username: 'compute',11- password: 'edge',12- hashFunction: (m: string) => SHA256(m).toString(),13- })14-)15-16-app.get('/', (c) => c.text('Hello! Compute@Edge!'))17-app.get('/auth/*', (c) => c.text('You are authorized!'))18-app.get('/hello/:name', (c) => {19- return c.text(`Hello ${c.req.param('name')}!!!!!`)20-})21-22-app.fire()deleted:examples/compute-at-edge/.gitignore-6 removed
1-/node_modules2-/bin3-/pkg4-fastly.toml5-package-lock.json6-yarn.lockdeleted:examples/compute-at-edge/build.js-21 removed
1-const { build } = require('esbuild')2-const globalsPlugin = require('@esbuild-plugins/node-globals-polyfill')3-const modulesPlugin = require('@esbuild-plugins/node-modules-polyfill')4-5-build({6- entryPoints: ['src/index.ts'],7- bundle: true,8- minify: true,9- outfile: 'bin/index.js',10- platform: 'node',11- plugins: [12- globalsPlugin.NodeGlobalsPolyfillPlugin({13- process: true,14- buffer: true,15- }),16- modulesPlugin.NodeModulesPolyfillPlugin(),17- ],18-}).catch((error) => {19- console.error(error)20- process.exit(1)21-})deleted:examples/compute-at-edge/fastly.example.toml-9 removed
1-# This file describes a Fastly Compute@Edge package. To learn more visit:2-# https://developer.fastly.com/reference/fastly-toml/3-4-authors = ["yusuke@kamawada.com"]5-description = "Hono example for Fastly Compute@Edge"6-language = "javascript"7-manifest_version = 28-name = ""9-service_id = ""deleted:examples/compute-at-edge/package.json-24 removed
1-{2- "name": "hono-example-compute-at-edge",3- "version": "0.0.1",4- "main": "index.js",5- "author": "yusuke@kamawada.com",6- "license": "MIT",7- "scripts": {8- "dev": "fastly compute serve --watch",9- "prebuild": "node ./build.js",10- "build": "js-compute-runtime --skip-pkg bin/index.js bin/main.wasm",11- "deploy": "npm run build && fastly compute deploy"12- },13- "devDependencies": {14- "@esbuild-plugins/node-globals-polyfill": "^0.1.1",15- "@esbuild-plugins/node-modules-polyfill": "^0.1.4",16- "@types/crypto-js": "^4.1.1",17- "esbuild": "^0.14.25"18- },19- "dependencies": {20- "@fastly/js-compute": "^0.2.4",21- "crypto-js": "^4.1.1",22- "hono": "^0.5.2"23- }24-}deleted:examples/compute-at-edge/README.md-47 removed
1-# Hono example for Fastly Compute@Edge2-3-This is an example project with Hono\[炎\] for Fastly Compute@Edge.4-5-## Features6-7-- Minimal8-- TypeScript9-- [esbuild](https://github.com/evanw/esbuild) to build10-- Fast11-- Live reload12-- Basic Auth middleware13-14-## Usage15-16-Install17-18-```19-$ yarn install20-```21-22-Rename and edit `fastly.toml`23-24-```25-$ mv fastly.example.toml fastly.toml26-$ code fastly.toml27-```28-29-Develop30-31-```32-$ yarn dev33-```34-35-Deploy36-37-```38-$ yarn deploy39-```40-41-## Author42-43-Yusuke Wada <https://github.com/yusukebe>44-45-## License46-47-MITdeleted:examples/durable-objects/src/counter.ts-35 removed
1-import { Hono } from '../../../src/index'2-3-export class Counter {4- value: number = 05- state: DurableObjectState6- app: Hono = new Hono()7-8- constructor(state: DurableObjectState) {9- this.state = state10- this.state.blockConcurrencyWhile(async () => {11- const stored = await this.state.storage?.get<number>('value')12- this.value = stored || 013- })14-15- this.app.get('/increment', async (c) => {16- const currentValue = ++this.value17- await this.state.storage?.put('value', this.value)18- return c.text(currentValue.toString())19- })20-21- this.app.get('/decrement', async (c) => {22- const currentValue = --this.value23- await this.state.storage?.put('value', this.value)24- return c.text(currentValue.toString())25- })26-27- this.app.get('/', async (c) => {28- return c.text(this.value.toString())29- })30- }31-32- async fetch(request: Request) {33- return this.app.fetch(request)34- }35-}deleted:examples/durable-objects/src/index.ts-26 removed
1-import { Hono } from 'hono'2-3-export { Counter } from './counter'4-5-declare module 'hono' {6- interface Env {7- COUNTER: DurableObjectNamespace8- }9-}10-11-const app = new Hono()12-13-app.get('*', async (c) => {14- const id = c.env.COUNTER.idFromName('A')15- const obj = c.env.COUNTER.get(id)16- const resp = await obj.fetch(c.req.url)17-18- if (resp.status === 404) {19- return c.text('404 Not Found', 404)20- }21-22- const count = parseInt(await resp.text())23- return c.text(`Count is ${count}`)24-})25-26-export default appdeleted:examples/durable-objects/.gitignore-5 removed
1-dist2-node_modules3-worker4-package-lock.json5-yarn.lockdeleted:examples/durable-objects/package.json-19 removed
1-{2- "private": true,3- "name": "hono-example-durable-objects",4- "version": "0.0.1",5- "main": "dist/index.js",6- "scripts": {7- "test": "echo \"Error: no test specified\" && exit 1",8- "dev": "wrangler dev src/index.ts",9- "deploy": "wrangler publish src/index.ts"10- },11- "license": "MIT",12- "devDependencies": {13- "@cloudflare/workers-types": "^3.0",14- "wrangler": "^0.0.17"15- },16- "dependencies": {17- "hono": "^0.5.1"18- }19-}deleted:examples/durable-objects/README.md-5 removed
1-# hono-example-durable-objects2-3-- Cloudflare Durable Objects4-- Module Worker Syntax5-- Using TypeScriptdeleted:examples/durable-objects/wrangler.toml-10 removed
1-name = "durable-objects-counter"2-type = "javascript"3-compatibility_date = "2022-02-12"4-5-[durable_objects]6-bindings = [{name = "COUNTER", class_name = "Counter"}]7-8-[[migrations]]9-tag = "v1" # Should be unique for each entry10-new_classes = ["Counter"]deleted:examples/jsx-ssr/src/components/footer.tsx-11 removed
1-import Nano from 'nano-jsx'2-3-export const Footer = () => {4- return (5- <footer>6- <address>7- Built with <a href='https://github.com/honojs/hono'>Hono</a>8- </address>9- </footer>10- )11-}deleted:examples/jsx-ssr/src/components/header.tsx-11 removed
1-import Nano from 'nano-jsx'2-3-export const Header = () => {4- return (5- <header>6- <h1>7- <a href='/'>Hono Example</a>8- </h1>9- </header>10- )11-}deleted:examples/jsx-ssr/src/pages/page.tsx-25 removed
1-import Nano from 'nano-jsx'2-import { Helmet } from 'nano-jsx'3-import { Header } from '../components/header'4-import { Footer } from '../components/footer'5-import type { Post } from '../index'6-7-type Props = {8- post: Post9-}10-11-export const Page = (props: Props) => {12- return (13- <div>14- <Helmet>15- <title>{props.post.title}</title>16- </Helmet>17- <Header />18- <main>19- <h2>{props.post.title}</h2>20- <p>{props.post.body}</p>21- </main>22- <Footer />23- </div>24- )25-}deleted:examples/jsx-ssr/src/pages/top.tsx-34 removed
1-import Nano from 'nano-jsx'2-import { Helmet } from 'nano-jsx'3-import { Header } from '../components/header'4-import { Footer } from '../components/footer'5-import type { Post } from '../index'6-7-type Props = {8- posts: Post[]9-}10-11-export const Top = (props: Props) => {12- return (13- <div>14- <Helmet>15- <title>Top</title>16- </Helmet>17- <Header />18- <main>19- <h2>Posts</h2>20- {props.posts}21- <ul>22- {props.posts.map((post) => {23- return (24- <li>25- <a href={`/post/${post.id}`}>{post.title}</a>26- </li>27- )28- })}29- </ul>30- </main>31- <Footer />32- </div>33- )34-}deleted:examples/jsx-ssr/src/index.tsx-46 removed
1-import { Hono } from 'hono'2-import Nano from 'nano-jsx'3-import { Page } from './pages/page'4-import { Top } from './pages/top'5-import { render } from './renderer'6-7-const app = new Hono()8-9-// Model10-export type Post = {11- id: string12- title: string13- body: string14-}15-16-const posts: Post[] = [17- { id: '1', title: 'Good Morning', body: 'Let us eat breakfast' },18- { id: '2', title: 'Good Afternoon', body: 'Let us eat Lunch' },19- { id: '3', title: 'Good Evening', body: 'Let us eat Dinner' },20- { id: '4', title: 'Good Night', body: 'Let us drink Beer' },21- { id: '5', title: 'こんにちは', body: '昼からビールを飲みます' },22-]23-24-// Logic25-const getPosts = () => posts26-27-const getPost = (id: string) => {28- return posts.find((post) => post.id == id)29-}30-31-// Controller32-app.get('/', (c) => {33- const posts = getPosts()34- const html = render(<Top posts={posts} />)35- return c.html(html)36-})37-38-app.get('/post/:id{[0-9]+}', (c) => {39- const id = c.req.param('id')40- const post = getPost(id)41- if (!post) return c.notFound()42- const html = render(<Page post={post} />)43- return c.html(html)44-})45-46-app.fire()deleted:examples/jsx-ssr/src/renderer.tsx-22 removed
1-import Nano from 'nano-jsx'2-import { Helmet } from 'nano-jsx'3-4-export const render = (component: any) => {5- const app = Nano.renderSSR(component)6- const { body, head, footer, attributes } = Helmet.SSR(app)7- const html = `8-<!DOCTYPE html>9-<html ${attributes.html.toString()}>10- <head>11- <meta charset="UTF-8">12- <meta name="viewport" content="width=device-width, initial-scale=1.0">13- <link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/mini.css/3.0.1/mini-default.min.css' />14- ${head.join('\n')}15- </head>16- <body ${attributes.body.toString()} style="padding: 1em 2em">17- ${body}18- ${footer.join('\n')}19- </body>20-</html>`21- return html22-}deleted:examples/jsx-ssr/.gitignore-5 removed
1-dist2-node_modules3-worker4-package-lock.json5-yarn.lockdeleted:examples/jsx-ssr/package.json-21 removed
1-{2- "name": "hono-example-jsx-ssr",3- "version": "0.0.1",4- "description": "",5- "main": "dist/index.js",6- "scripts": {7- "build": "esbuild --bundle --sourcemap --outdir=dist ./src/index.tsx",8- "dev": "miniflare --live-reload --debug",9- "deploy": "wrangler publish dist/index.js"10- },11- "license": "MIT",12- "dependencies": {13- "hono": "^0.5.1",14- "nano-jsx": "^0.0.29"15- },16- "devDependencies": {17- "esbuild": "^0.14.25",18- "miniflare": "2.2.0",19- "wrangler": "^0.0.16"20- }21-}deleted:examples/jsx-ssr/tsconfig.json-6 removed
1-{2- "compilerOptions": {3- "jsx": "react",4- "jsxFactory": "Nano.h",5- }6-}deleted:examples/jsx-ssr/wrangler.toml-10 removed
1-name = "hono-example-jsx-ssr"2-type = "javascript"3-4-compatibility_date = "2022-01-08"5-6-[build]7-command = "yarn run build"8-9-[build.upload]10-format = "service-worker"deleted:examples/mustache/src/index.js-16 removed
1-import { Hono } from 'hono'2-import { mustache } from 'hono/mustache'3-4-const app = new Hono()5-6-app.use('*', mustache())7-8-app.get('/', (c) => {9- return c.render(10- 'index',11- { name: 'Hono[炎]', title: 'Hono mustache example' }, // Parameters12- { footer: 'footer', header: 'header' } // Partials13- )14-})15-16-app.fire()deleted:examples/mustache/view/footer.mustache-2 removed
1- </body>2-</html>deleted:examples/mustache/view/header.mustache-7 removed
1-<!DOCTYPE html>2-<html>3- <head>4- <meta charset="utf-8" />5- <title>{{title}}</title>6- </head>7- <body>deleted:examples/mustache/view/index.mustache-3 removed
1-{{> header}}2-<h1>Hello! {{name}}</h1>3-{{> footer}}deleted:examples/mustache/.gitignore-6 removed
1-dist2-node_modules3-worker4-workers-site5-package-lock.json6-yarn.lockdeleted:examples/mustache/package.json-18 removed
1-{2- "name": "hono-example-mustache",3- "version": "0.0.1",4- "main": "src/index.js",5- "scripts": {6- "test": "echo \"Error: no test specified\" && exit 1",7- "dev": "wrangler dev src/index.js",8- "deploy": "wrangler publish src/index.js"9- },10- "license": "MIT",11- "dependencies": {12- "hono": "^0.5.1",13- "mustache": "^4.2.0"14- },15- "devDependencies": {16- "wrangler": "^0.0.16"17- }18-}deleted:examples/mustache/wrangler.toml-5 removed
1-name = "hono-example-mustache"2-compatibility_date = "2022-02-12"3-4-[site]5-bucket = "./view"deleted:examples/serve-static/assets/static/demo/index.html-6 removed
1-<html>2- <body>3- <h1>Hello Hono!</h1>4- <img src="/static/images/dinotocat.png" alt="Dinotocat" />5- </body>6-</html>deleted:examples/serve-static/assets/static/images/dinotocat.pngbinary
A binary file, deleted.
deleted:examples/serve-static/assets/static/hello.txt-1 removed
1-This is hello.txt! You can access: /static/demo/deleted:examples/serve-static/src/index.js-9 removed
1-import { Hono } from 'hono'2-import { serveStatic } from 'hono/serve-static'3-4-const hono = new Hono()5-6-hono.use('/static/*', serveStatic({ root: './' }))7-hono.get('/', (c) => c.text('This is Home! You can access: /static/hello.txt'))8-9-hono.fire()deleted:examples/serve-static/.gitignore-5 removed
1-dist2-node_modules3-worker4-package-lock.json5-yarn.lockdeleted:examples/serve-static/package.json-18 removed
1-{2- "name": "hono-example-serve-static",3- "version": "0.0.1",4- "description": "",5- "main": "src/index.js",6- "scripts": {7- "test": "echo \"Error: no test specified\" && exit 1",8- "dev": "wrangler dev src/index.js",9- "deploy": "wrangler publish src/index.js"10- },11- "license": "MIT",12- "dependencies": {13- "hono": "^0.5.1"14- },15- "devDependencies": {16- "wrangler": "^0.0.16"17- }18-}deleted:examples/serve-static/wrangler.toml-5 removed
1-name = "hono-example-serve-static"2-compatibility_date = "2022-02-12"3-4-[site]5-bucket = "./assets"modified:src/middleware/mustache/README.md+1 added-1 removed
66 unmodified lines67 ```68 69 ## Example70 71-<https://github.com/honojs/hono/tree/master/examples/mustache>71+<https://github.com/honojs/examples/tree/master/mustache-template>modified:src/middleware/serve-static/README.md+1 added-1 removed
37 unmodified lines38 ```39 40 ## Example41 42-<https://github.com/honojs/hono/tree/master/examples/serve-static>42+<https://github.com/honojs/examples/tree/master/serve-static>