https://discord.cloudflare.com logo
Join Discord
Powered by
# workers-discussions
  • m

    Mozzy

    04/25/2023, 6:14 PM
    Or perhaps
    CF-Connecting-IP
    instead
  • a

    Arthur

    04/25/2023, 7:18 PM
    Any one know if you can "statically" cache a workers endpoint response? Eg, I have data that only changes 24 times a day. Can I cache the endpoint response to be the same, and that my worker only gets invoked once every hour?
  • a

    Arthur

    04/25/2023, 7:20 PM
    For my use case I want to build my own cache layer over another api to not overload that service with calls which finally result in the same response.
  • u

    Unsmart | Tech debt

    04/25/2023, 7:20 PM
    Workers run before the cache and thus cannot be cached. You have to use the cache api inside of workers to cache anything and since its programmatic the possibilities of how to use it are pretty much infinite
  • u

    Unsmart | Tech debt

    04/25/2023, 7:21 PM
    and for caching fetch requests:
  • u

    Unsmart | Tech debt

    04/25/2023, 7:21 PM
    https://developers.cloudflare.com/workers/examples/cache-using-fetch/#main
  • a

    Arthur

    04/25/2023, 7:22 PM
    This is perfect
  • x

    xbtc

    04/25/2023, 10:43 PM
    I'm new to cloudflare. I built a worker, and this script addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)); }); async function handleRequest(request) { const { pathname } = new URL(request.url); if ( !pathname.includes('market-analysis') ) { return fetch(request); } return new Response('Hello, World!', { headers: { 'Content-Type': 'text/plain' }, }); } then i added a route for mydomain.com/* My question now is, Can i read content from a file in the worker, and if not, how can i link it up with a page, and its content. Sorry for the noob question,
  • s

    sathoro

    04/26/2023, 2:15 AM
    Workers don't have access to the filesystem. You have to include the file contents in your script or do a fetch to an external resource
  • d

    dave

    04/26/2023, 2:29 AM
    Is it possible to use aws4fetch to implement AWS v4 signature authentication on a backend?
  • d

    dave

    04/26/2023, 2:29 AM
    Basically as a server instead of client.
  • f

    frankjonen

    04/26/2023, 4:25 AM
    Re: EmailWorkers. Are these OK to use for contact forms?
  • z

    zegevlier

    04/26/2023, 5:34 AM
    I see no reason why not. What makes you ask?
  • l

    Lloyd

    04/26/2023, 11:30 AM
    I see that in the typescript docs for page functions and the example typescript for a worker have different return types. Is there a reason for this? Which should I use?
  • h

    HardAtWork

    04/26/2023, 11:34 AM
    Neither of them explicitly define return types, if that is what you mean?
  • l

    Lloyd

    04/26/2023, 11:34 AM
    sorry you're right not return types but yeah, they use different types
  • w

    Walshy | Pages

    04/26/2023, 11:35 AM
    if you're using Pages Functions you use the Functions syntax/types
  • w

    Walshy | Pages

    04/26/2023, 11:35 AM
    if Workers, the Workers syntax/types
  • h

    HardAtWork

    04/26/2023, 11:35 AM
    That's because
    PagesFunction
    passes everything into a single
    ctx
    object, while the
    ExportedHandler
    supports the many handlers that a Worker can run:
    fetch
    ,
    scheduled
    ,
    queue
    , etc.
  • h

    HardAtWork

    04/26/2023, 11:36 AM
    They use a different syntax, so they get different types
  • l

    Lloyd

    04/26/2023, 11:36 AM
    OK, are both capable of using queues?
  • h

    HardAtWork

    04/26/2023, 11:36 AM
    If you want to use the
    ExportedHandler
    type while writing Functions, then you can use Advanced Mode
  • h

    HardAtWork

    04/26/2023, 11:37 AM
    Functions is capable of pushing to a Queue, but it is not capable of being a Queue consumer
  • l

    Lloyd

    04/26/2023, 11:37 AM
    Got it, and this is maybe a dumb question but if I'm using Pages can I still have a Worker that isnt a Function, to consume a queue?
  • h

    HardAtWork

    04/26/2023, 11:38 AM
    Yup, though that won't be deployed automagically by Pages CI(the Github/Gitlab integration).
  • l

    Lloyd

    04/26/2023, 11:39 AM
    I see, so even if they are all in the same repo, I'd need to add a build step to use I think wrangler cli to deploy the worker from github actions?
  • h

    HardAtWork

    04/26/2023, 11:40 AM
    Not necessarily. You can add a extra step in your Pages build command that deploys the Worker, it just won't happen automatically
  • l

    Lloyd

    04/26/2023, 11:41 AM
    OK I think I'm getting it thanks, one of those steps could be the wrangler command to deploy the Worker?
  • h

    HardAtWork

    04/26/2023, 11:41 AM
    Yup
  • l

    Lloyd

    04/26/2023, 11:47 AM
    Cool I'll give it a try
1...241724182419...2509Latest