Skip to content

Commit

Permalink
chore: Add serve static example (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Jan 21, 2022
1 parent 034bf6d commit 2ac54b7
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 0 deletions.
5 changes: 5 additions & 0 deletions example/serve-static/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist
node_modules
worker
package-lock.json
yarn.lock
27 changes: 27 additions & 0 deletions example/serve-static/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "hono-example-serve-static",
"version": "0.0.1",
"description": "",
"main": "dist/worker.js",
"scripts": {
"test": "jest --verbose",
"build": "rimraf tsc && wrangler build",
"dev": "tsc && npm-run-all --parallel dev:*",
"dev:tsc": "tsc --watch",
"dev:wrangler": "wrangler dev"
},
"author": "Yusuke Wada <[email protected]> (https://github.com/yusukebe)",
"license": "MIT",
"dependencies": {
"@cloudflare/kv-asset-handler": "^0.2.0",
"hono": "*"
},
"devDependencies": {
"@cloudflare/workers-types": "^3.3.0",
"@cloudflare/wrangler": "^1.19.7",
"npm-run-all": "^4.1.5",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
}
}
18 changes: 18 additions & 0 deletions example/serve-static/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Hono } from '../../../dist'
import { getAssetFromKV } from '@cloudflare/kv-asset-handler'

const hono = new Hono()

hono.get('/', (c) => c.text('This is Home! You can access: /static/hello.txt'))

hono.all('/static/*', async (c) => {
try {
return await getAssetFromKV(c.event)
} catch (e) {
return c.newResponse('Asset Not Found', {
status: 404,
})
}
})

hono.fire()
1 change: 1 addition & 0 deletions example/serve-static/static/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is hello.txt!
21 changes: 21 additions & 0 deletions example/serve-static/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"rootDir": "src",
"outDir": "./dist",
"allowJs": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"types": [
"@cloudflare/workers-types",
]
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
]
}
4 changes: 4 additions & 0 deletions example/serve-static/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
target: 'webworker',
entry: './dist/index.js',
}
13 changes: 13 additions & 0 deletions example/serve-static/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "hono-example-serve-static"
type = "webpack"
route = ''
zone_id = ''
usage_model = ''
compatibility_flags = []
workers_dev = true
compatibility_date = "2022-01-09"
webpack_config = "webpack.config.js"

[site]
bucket = "./"
entry-point = "./"

0 comments on commit 2ac54b7

Please sign in to comment.