Comments (6)
The equivalent code with module workers would look like this:
import { getAssetFromKV, NotFoundError, MethodNotAllowedError } from '@cloudflare/kv-asset-handler'
import manifestJSON from '__STATIC_CONTENT_MANIFEST'
const assetManifest = JSON.parse(manifestJSON)
export default {
async fetch(request, env, ctx) {
const response = await getAssetFromKV({
request,
waitUntil(promise) {
return ctx.waitUntil(promise)
},
},
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: assetManifest,
});
return response;
},
}
It's a bit more verbose given the age of this module and being designed for older standards, but that's how I'm using it in production in various projects today.
from kv-asset-handler.
Hi @Cherry thanks for the response
I dropped in the code, but I'm getting a bug on:
import manifestJSON from '__STATIC_CONTENT_MANIFEST'
Here are the error logs, might you have a suggestion? Thanks!
ERROR in ./index.js 2:0-52
Module not found: Error: Can't resolve '__STATIC_CONTENT_MANIFEST' in '/github/workspace'
resolve '__STATIC_CONTENT_MANIFEST' in '/github/workspace'
Parsed request is a module
using description file: /github/workspace/package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
looking for modules in /github/workspace/node_modules
single file module
using description file: /github/workspace/package.json (relative path: ./node_modules/__STATIC_CONTENT_MANIFEST)
no extension
Field 'browser' doesn't contain a valid alias configuration
/github/workspace/node_modules/__STATIC_CONTENT_MANIFEST doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
/github/workspace/node_modules/__STATIC_CONTENT_MANIFEST.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
/github/workspace/node_modules/__STATIC_CONTENT_MANIFEST.json doesn't exist
.wasm
Field 'browser' doesn't contain a valid alias configuration
/github/workspace/node_modules/__STATIC_CONTENT_MANIFEST.wasm doesn't exist
/github/workspace/node_modules/__STATIC_CONTENT_MANIFEST doesn't exist
/github/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
webpack 5.75.0 compiled with 1 error in 11783 ms
✘ [ERROR] Command failed with exit code 1: npm run build
from kv-asset-handler.
Can you share a minimal reproduction? My example works with wrangler and its built-in bundler (esbuild). If you're using another bundler like webpack
(as it looks like you are in your build logs), you will need to mark the dependency as "external".
from kv-asset-handler.
Quick question, do I need to create a actual file called
__STATIC_CONTENT_MANIFEST
that has some parameters in it?
from kv-asset-handler.
No. That "file" is handled and uploaded by wrangler
when you publish the worker. You just need to make sure it's marked as "external" if you're using a custom bundler like webpack.
from kv-asset-handler.
This is falling out of scope for this repository, but you should be able to completely nuke that file and use just a standard wrangler2
build, with node_compat
. I'd recommend joining the Cloudflare Discord and asking this there.
from kv-asset-handler.
Related Issues (20)
- Error in documentation (re: ETags) HOT 3
- Failed to execute 'cancel' on 'ReadableStream': parameter 1 is not of type 'Value'. HOT 1
- Serve different assets any given `requestKey`, even if those are in the `ASSET_MANIFEST` HOT 3
- kv-asset-handler can translate 206 responses to 200 responses HOT 2
- /(non-ascii)/index.html cannot be referenced if index.html is omitted HOT 4
- mapRequestToAsset give 404`s on Gatsby projects HOT 3
- Not compatible with the new ES6 module worker format HOT 9
- 0.1.3 release not published to NPM HOT 3
- Falling back to single-page application 404 page for static assets HOT 2
- Not returning 304 status code for cached response, instead 200 in KV worker HOT 3
- Performance for images HOT 2
- "Environment doesnt support readable streams" HOT 2
- cutting a new release HOT 7
- `bypassCache: false` does not work with Modules worker? HOT 2
- Confusing fallback in mapRequestToAssets HOT 1
- Content length undefined when edge cache HOT 1
- .well-known/apple-app-site-association is not served/fetched HOT 1
- Responding with custom status codes HOT 1
- struggling with understanding how to transition from service worker to module HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kv-asset-handler.