chore: fix hono-example-blog (#100)
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 f51d0f0 · Browse files · 8 files·+100 added−74 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+100 added−74 removed
- other:+100 added−74 removed
Provenance
- Commit
39ed68b- Tree
f5b6fe3- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
f51d0f0
8 files changed+100 added−74 removed
modified:examples/blog/src/controller.ts+7 added-7 removed
1123445678891011121313141516174 unmodified lines22232425262627282930313233343535363738392 unmodified lines424344454646474849504 unmodified linesimport type { Handler } from '../../../dist'import type { Context, Handler } from 'hono'import * as Model from './model'
export const root: Handler = (c) => {export const root: Handler = (c: Context) => { return c.json({ message: 'Hello' })}
export const list: Handler = async (c) => {export const list: Handler = async (c: Context) => { const posts = await Model.getPosts() return c.json({ posts: posts, ok: true })}
export const create: Handler = async (c) => {export const create: Handler = async (c: Context) => { let newPost: Model.Post | undefined if (c.req.parsedBody) { const param = c.req.parsedBody as Model.Param newPost = await Model.createPost(param)4 unmodified lines } return c.json({ post: newPost, ok: true }, 201)}
export const show: Handler = async (c) => {export const show: Handler = async (c: Context) => { 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: Handler = async (c) => {export const update: Handler = async (c: Context) => { const id = c.req.param('id') if (!(await Model.getPost(id))) { // 204 No Content return c.json({ ok: false }, 204)2 unmodified lines const success = await Model.updatePost(id, param) return c.json({ ok: success })}
export const destroy: Handler = async (c) => {export const destroy: Handler = async (c: Context) => { const id = c.req.param('id') if (!(await Model.getPost(id))) { // 204 No Content return c.json({ ok: false }, 204)4 unmodified linesmodified:examples/blog/src/index.ts+4 added-3 removed
12312345678912 unmodified linesimport { Hono } from '../../../dist'import { bodyParse } from '../../../dist/middleware/body-parse/body-parse'import { cors } from '../../../dist/middleware/cors/cors'import { Hono } from 'hono'
import { bodyParse } from 'hono/body-parse'import { cors } from 'hono/cors'
import * as Controller from './controller'
export const app = new Hono()
12 unmodified linesmodified:examples/blog/jest.config.js+3 added-2 removed
1223455678module.exports = { testEnvironment: 'miniflare', // ✨ testEnvironment: 'miniflare', testMatch: ['**/test/**/*.+(ts|tsx|js)', '**/src/**/(*.)+(spec|test).+(ts|tsx|js)'], transform: { '^.+\\.(ts|tsx)$': 'ts-jest', '^.+\\.(ts|tsx)$': 'esbuild-jest', }, resolver: 'jest-node-exports-resolver',}modified:examples/blog/package.json+15 added-17 removed
123455678978910111213141415161717181920212223242526271819202122232425262927{ "name": "hono-example-blog", "version": "0.0.1", "description": "", "main": "dist/worker.js", "main": "dist/index.js", "scripts": { "test": "jest --verbose", "build": "wrangler build", "dev": "miniflare" "build": "esbuild --bundle --outdir=dist ./src/index.ts", "dev": "miniflare --live-reload --watch --debug", "publish": "wrangler publish dist/index.js", "test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose" }, "author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)", "license": "MIT", "dependencies": { "hono": "*" "hono": "^0.3.7" }, "devDependencies": { "@cloudflare/workers-types": "^3.3.0", "@cloudflare/wrangler": "^1.19.7", "@types/jest": "^27.4.0", "jest": "^27.4.7", "jest-environment-miniflare": "^2.0.0", "miniflare": "2.2.0", "ts-jest": "^27.1.2", "ts-loader": "~8.2.0", "typescript": "^4.5.4", "webpack": "~4.44.1", "webpack-cli": "^4.9.1" "@cloudflare/workers-types": "^3.3.1", "esbuild": "^0.14.21", "esbuild-jest": "^0.5.0", "jest": "^27.5.0", "jest-environment-miniflare": "^2.2.0", "jest-node-exports-resolver": "^1.1.5", "miniflare": "^2.2.0", "wrangler": "^0.0.15" }}No newline at end of file}modified:examples/blog/README.md+62 added-1 removed
1233456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475# hono-example-blog
- CRUDCRUD web API for Blog.
## Features
- Cloudflare Workers- KV- TypeScript- `esbuild` for build- `miniflare` for development- `wrangler@beta` for deploy- Test with Jest `miniflare environment`
## Endpoints
- `GET /posts`- `POST /posts`- `GET /posts/:id`- `PUT /posts/:id`- `DELETE /posts/:id`
## Usage
Install dependencies:
```sh$ yarn run install```
Rename `wrangler.example.toml` to `wrangler.toml`:
```sh$ mv wrangler.example.toml wrangler.toml```
Setup KV:
```sh$ wrangler kv:namespace create BLOG_EXAMPLE --preview
🌀 Creating namespace with title "hono-example-blog-BLOG_EXAMPLE_preview"✨ Success!Add the following to your configuration file in your kv_namespaces array:{ binding = "BLOG_EXAMPLE", preview_id = "xxxxxxxxxx" }```
```sh$ wrangler kv:namespace create BLOG_EXAMPLE
🌀 Creating namespace with title "hono-example-blog-BLOG_EXAMPLE"✨ Success!Add the following to your configuration file in your kv_namespaces array:{ binding = "BLOG_EXAMPLE", id = "yyyyyyyyyy" }```
Copy KV id:
```tomlkv_namespaces = [ { binding = "BLOG_EXAMPLE", preview_id = "xxxxxxxxxx", id = "yyyyyyyyy" }]```
Run a development server:
```sh$ yarn run dev```
Publish:
```sh$ yarn run publih```deleted:examples/blog/tsconfig.json-22 removed
12345678910111213141516171819202122{ "compilerOptions": { "target": "es2017", "module": "commonjs", "rootDir": "src", "outDir": "./dist", "allowJs": true, "strict": true, "esModuleInterop": true, "skipLibCheck": true, "types": [ "@cloudflare/workers-types", "@types/jest", ] }, "include": [ "src/**/*" ], "exclude": [ "node_modules", ]}No newline at end of filedeleted:examples/blog/webpack.config.js-15 removed
123456789101112131415module.exports = { target: 'webworker', entry: './src/index.ts', module: { rules: [ { test: /\.ts$/, loader: 'ts-loader', }, ], }, resolve: { extensions: ['.ts', '.js'], },}modified:examples/blog/wrangler.example.toml+9 added-7 removed
1234562389456789101112131415name = "hono-example-blog"type = "webpack"route = ''zone_id = ''usage_model = ''compatibility_flags = []type = "javascript"workers_dev = truecompatibility_date = "2022-01-09"webpack_config = "webpack.config.js"
compatibility_date = "2022-02-03"
kv_namespaces = [ { binding = "BLOG_EXAMPLE", preview_id = "", id = "" }]
[build]command = "yarn run build"
[build.upload]format = "service-worker"No newline at end of file