-
-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add serve static example (#61)
- Loading branch information
Showing
7 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dist | ||
node_modules | ||
worker | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is hello.txt! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
target: 'webworker', | ||
entry: './dist/index.js', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "./" |