Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.

Conversation

@threepointone
Copy link
Contributor

@threepointone threepointone commented Nov 7, 2021

This PR provides a possible solution for getting Workers Sites working with ES Module workers. This approach is not as invasive as other approaches, so isn't as risky either.

Usage:

import manifestJSON from "__STATIC_CONTENT_MANIFEST";
const manifest = JSON.parse(manifestJSON);

export default {
  fetch(request, env, ctx) {
    return await getAssetFromKV(
      {
        request,
        waitUntil(promise) {
          return ctx.waitUntil(promise);
        },
      },
      {
        ASSET_NAMESPACE: env.ASSET_NAMESPACE,
        ASSET_MANIFEST: manifest,
      }
    );
    // ...
  },
};

I'll also send a PR to wrangler that adds the manifest as a text module __STATIC_CONTENT_MANIFEST to the worker.

cc @xortive Is this approach right? It's following your comment here cloudflare/wrangler-legacy#1938 (comment)

This PR provides a possible solution for getting Workers Sites working with ES Module workers. This approach is not as invasive as other approaches.

Usage:

```
import manifestJSON from '__STATIC_CONTENT_MANIFEST'
const manifest = JSON.parse(manifestJSON)

export default {
  fetch(request, env, ctx){
    return await getAssetFromKV({request, waitUntil: ctx.waitUntil}, {
      ASSET_NAMESPACE: env.ASSET_NAMESPACE,
      ASSET_MANIFEST: manifest
    })
    // ...
  }
}
```

I'll also send a PR to wrangler that adds the manifest as a text module to the worker.
@threepointone
Copy link
Contributor Author

You don't even have to merge this PR really, just to be more accurate about the type signature

@threepointone threepointone requested a review from Cherry November 7, 2021 05:02
Comment on lines +106 to +110

type Evt = {
request: Request
waitUntil: (promise: Promise<any>) => void
}
Copy link
Contributor

@SukkaW SukkaW Nov 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why custom Evt type? You know @cloudflare/workers-types will eventually release a new version, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose the word "Evt" to be familiar, and @cloudflare/workers-types won't ever define the types for kv-asset-handler.

@Cherry Cherry mentioned this pull request Nov 9, 2021
Copy link
Contributor

@Cherry Cherry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks!

@threepointone threepointone merged commit fd27ccf into master Nov 9, 2021
@threepointone threepointone deleted the es-worker-compat branch November 9, 2021 17:13
@nataliescottdavidson nataliescottdavidson mentioned this pull request Nov 9, 2021
@Cherry Cherry mentioned this pull request Nov 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants