Skip to content

getContentFromKVAsset yields an undefined __STATIC_CONTENT_MANIFEST error while serveStatic works. #1134

Answered by yusukebe
yudai-nkt asked this question in Q&A
Discussion options

You must be logged in to vote

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 @cloudflare/kv-asset-handler:

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@yudai-nkt
Comment options

Answer selected by yudai-nkt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants