Giter Site home page Giter Site logo

Comments (2)

sinitsa avatar sinitsa commented on June 16, 2024 1

Thank you so much!
I catch error with fetch (i gave additional invalid mode=cors header param, it's works on local dev but fails on worker)
And finally i make it works with context.env.BINDING KV access in loader, thank you, i understood about module worker difference, planning to dig deeper to Durable Objects, thank you so much for showing me the way ) and big thanks for excellent quality template)

from remix-cloudflare-template.

edmundhung avatar edmundhung commented on June 16, 2024

Hi @sinitsa,

I have tested fetch(), and axios request - in routes files - everything same - at worker, any request did't get any response... at local dev (miniflare) everything ok ....

I am not sure exactly what's the problem you had here. I haven't try using axios with worker myself. But I do think it might be hard to get it working correctly on the Worker runtime. I would strongly suggest using the native fetch instead.

and by the way, how i can use Cloudflare KV read/writ in *.server.ts files? I have added everything as usually but in this template seems like something works bit different...

I guess you might be trying to access the KV bindings as global variables. However, this approach is limited to service worker (which the official remix worker template is based on), while this template is setup as a module worker. You can find out more details about module worker here. I understand this is probably quite confusing to new users experimenting Cloudlfare Workers. But in general, you can consider module worker as the latest and suggested approach going forward to implement your workers logic. There are also additional benefits with this approach. For example, module workers support Durable Objects and works with Pages directly as well.

Back to your question, in order to access the KV binding, you will need to access it through the env object similar to the example here. This approache should allow you to access it on loader and action which is usually where you need the data from KV.

Let me know if you have any more questions. It will be helpful if you can provide more details/code on how you are doing it.

from remix-cloudflare-template.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.