-
I want to use import { Hono } from "hono";
import { serveStatic } from "hono/cloudflare-workers";
import { getContentFromKVAsset } from "hono/utils/cloudflare";
const app = new Hono();
app
.get("/static/*", serveStatic({ root: "./" }))
.get("/hello", async (c) => {
await getContentFromKVAsset("/static/hello.txt");
return c.text("Success!");
});
export default app; and the following setup: $ cat wrangler.toml
[site]
bucket = "./assets"
$ cat assets/static/hello.txt
Hello world! The
Since Could anyone help me fix this? |
Beta Was this translation helpful? Give feedback.
Answered by
yusukebe
May 26, 2023
Replies: 1 comment 1 reply
-
Hi @yudai-nkt ! Try this: import { Hono } from 'hono'
import { serveStatic } from 'hono/cloudflare-workers'
import { getContentFromKVAsset } from 'hono/utils/cloudflare'
// @ts-ignore
import manifestJSON from '__STATIC_CONTENT_MANIFEST'
type Bindings = {
__STATIC_CONTENT: KVNamespace
}
const app = new Hono<{ Bindings: Bindings }>()
app.get('/static/*', serveStatic({ root: './' })).get('/hello', async (c) => {
const content = await getContentFromKVAsset('static/hello.txt', {
manifest: manifestJSON,
namespace: c.env.__STATIC_CONTENT
})
c.header('Content-Type', 'text/plain')
return c.body(content)
})
export default app You can refer |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
yudai-nkt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @yudai-nkt !
Try this:
You can refer
@cloudflare/kv-asset-handler
: