question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hi,

I’d like to use Cloudflare Workers as a CDN like explained on this tutorial: https://developers.cloudflare.com/workers/tutorials/configure-your-cdn (full code at the end)

it works well without Worktop but I did not find out how to make it work with worktop as I just received the JSON body property instead of the binary:

{
    "locked": false
}

I wonder what would be the equivalent of response = new Response(response.body, { ...response, headers }) with worktop. Here is the actual code:

API.add("GET", "/assets/:id", async (req, res) => {
  const response = await fetch("https://f001.backblazeb2.com/file/asset/file.jpg");
  res.send(200, response.body);
});

Cache.listen(API.run);

Any idea ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Jan 9, 2022

Yes that method auto-casts the input to standard/common formats. That’s why end() is available and why you can also directly return Responses from handlers

0reactions
mediarlcommented, Jan 9, 2022

If I use res.send(200, response.body, {...}, I then get that response:

{
    "locked": false
}

I dont think you can get the raw bytes without calling blob() first. Also it seems that send function (in response) can’t handle binary content:

if (data == null) {
	data = '';
} else if (dtype === 'object') {
	data = JSON.stringify(data);
	type = type || 'application/json;charset=utf-8';
} else if (dtype !== 'string') {
	data = String(data);
}

This is why I used end function directly

Read more comments on GitHub >

github_iconTop Results From Across the Web

Binary Cache - NixOS Wiki
A binary cache builds Nix packages and caches the result for other machines. Any machine with Nix installed can be a binary cache...
Read more >
Binary Caching - vcpkg
Binary caching is a vcpkg feature that saves copies of library binaries in a shared location that can be accessed by vcpkg for...
Read more >
Introducing the Spack Rolling Binary Cache hosted on AWS
The Binary Cache lets you install a package based upon an existing installation, rather than having to recompile it from source. As Spack...
Read more >
grab/cocoapods-binary-cache - GitHub
CocoaPods binary cache. Test License Gem. A plugin that helps to reduce the build time of Xcode projects which use CocoaPods by prebuilding...
Read more >
Cache introduction - Washington
With our four-byte cache we would inspect the two least significant bits of our memory addresses. ▫ Again, you can see that address...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found