kv-asset-handler | Routes requests to KV assets | Key Value Database library
kandi X-RAY | kv-asset-handler Summary
kandi X-RAY | kv-asset-handler Summary
kv-asset-handler is an open-source library for managing the retrieval of static assets from Workers KV inside of a Cloudflare Workers function. kv-asset-handler is designed for use with Workers Sites, a feature included in Wrangler, our command-line tool for deploying Workers projects. kv-asset-handler runs as part of a Cloudflare Workers function, so it allows you to customize how and when your static assets are loaded, as well as customize how those assets behave before they're sent to the client.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of kv-asset-handler
kv-asset-handler Key Features
kv-asset-handler Examples and Code Snippets
Community Discussions
Trending Discussions on kv-asset-handler
QUESTION
My cloudflare workers site houses binary data that a react app fetches. This binary data is stored as gzip compressed as it compresses extremely well (we're talking about a 20-25x reduction and uncompressed it is too large to fit in the 10MB KV limit). The problem I'm running into is that either the worker returns the data without the appropriate header:
...ANSWER
Answered 2020-Nov-15 at 20:54This is an unfortunate wart of the Service Workers spec -- it's designed for use in the browser, where it expects response bodies to be decompressed before the worker runs, and does not expect they will be transmitted over the network again. To make things consistent, Cloudflare Workers has to recompress the data according to the content-encoding
header when transmitting. But this in turn means there's no way to serve data that is already compressed.
To solve this, we (Cloudflare) have added a non-standard Response
option called encodeBody
, which can be "auto"
(the default) or "manual"
(assumes the body is already compressed).
So you can write code like this:
QUESTION
I have a following wrangler.toml
. When I would like to use dev
or preview
(e.g. npx wrangler dev
or npx wrangler preview
) wrangler asks to add a preview_id
to the KV namespaces. Is this an identifier to an existing KV namespace?
I see there is a ticket in Cloudflare Workers GH at https://github.com/cloudflare/wrangler/issues/1458 that tells this ought to be clarified but the ticket is closed with adding an error message
In order to preview a worker with KV namespaces, you must designate a preview_id in your configuration file for each KV namespace you'd like to preview."
which is the reason I'm here. :)
As for larger context I would be really glad if someone could clarify: I see that if I give a value of an existing namespace, I can preview and I see a KV namespace of type __some-worker-dev-1234-workers_sites_assets_preview
is generated in Cloudflare. This has a different identifier than the KV namespace pointed by the identifier used in the preview_id
and the KV namespace pointed by the identifier I used in preview_id
is empty. Why does giving an identifier of an existing KV namespace remove the error message, deploys the assets and allow for previwing but the actual KV namespace is empty and a new one is created?
How do does kv-asset-handler know to look into this generated namespace to retrieve the assets?
I'm currently testing with the default generated Cloudare Worker to my site and I wonder if I have misunderstood something or if there is some mechanics that bundles during preview/publish the site namespace to the scipt.
If there is some random mechanics with automatic mapping, can this be then so that every developer can have their own private preview KV namespace?
...ANSWER
Answered 2020-Aug-10 at 16:45This answer applies to versions of Wrangler >= 1.10.0
wrangler asks to add a preview_id to the KV namespaces. Is this an identifier to an existing KV namespace?
Yes! The reason there is a different identifier for preview namespaces is so that when developing with wrangler dev
or wrangler preview
you don't accidentally write changes to your existing production data with possibly buggy or incompatible code. You can add a --preview
flag to most wrangler kv
commands to interact with your preview namespaces.
For your situation here there are actually a few things going on.
- You are using Workers Sites
- You have a KV namespace defined in
wrangler.toml
Workers Sites will automatically configure a production namespace for each environment you run wrangler publish
on, and a preview namespace for each environment you run wrangler dev
or wrangler preview
on. If all you need is Workers Sites, then there is no need at all to specify a kv-namepsaces
table in your manifest. That table is for additional KV namespaces that you may want to read data from or write data to. If that is what you need, you'll need to configure your own namespace and add id
to wrangler.toml
if you want to use wrangler publish
, and preview_id
(which should be different) if you want to use wrangler dev
or wrangler preview
.
QUESTION
I am struggling to get an SPA working using Angular with Cloudflare's Workers Sites. I am following the tutorial found here (but supplementing steps for Angular- not React), and everything is fine until however once published I am getting the browser error - could not find index.html in your content namespace
My troubleshooting thus far has let me to link below:
https://github.com/cloudflare/kv-asset-handler#servesinglepageapp
however I am unsure how to configure/use this guidance for Angular so that it solves my above problem.
...ANSWER
Answered 2020-Feb-28 at 03:42The wrangler.toml
file should have the build folder on [site].bucket
pointing to ./dist/
instead of ./build
as seen in the guide.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install kv-asset-handler
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page