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

    lattenb

    04/20/2023, 4:22 PM
    Anyone have an idea why console.log would be forwarded through worker logpush but using a library like loglevel wouldn't (which uses console.log under the hood)
  • a

    amorfati

    04/20/2023, 5:41 PM
    does a JSON schema from
    wrangler.json
    exists somewhere? https://developers.cloudflare.com/workers/wrangler/configuration/
  • s

    Skye

    04/20/2023, 5:44 PM
    Not currently
  • s

    Skye

    04/20/2023, 5:44 PM
    But it's something that was being talked about
  • s

    Skye

    04/20/2023, 5:44 PM
    I'd recommend you make an issue, asking for support!
  • c

    C o m f i i

    04/20/2023, 6:51 PM
    Is it ever common to call a worker from another worker that's a cron trigger?
  • c

    C o m f i i

    04/20/2023, 6:54 PM
    I'm thinking of creating a worker with a cron trigger, that's simply responsible for calling the worker function from a schedule. the worker function i'm calling on a schedule will be using Hono, and will have more complex operations. I was thinking it might be nice to separate the concerns, and have one cron trigger worker just designated to calling the worker
  • u

    Unsmart | Tech debt

    04/20/2023, 7:07 PM
    Not sure why you wouldnt just run the code directly in the cron but you can use service bindings
  • k

    kian

    04/20/2023, 7:08 PM
    Depending on what you need in your
    fetch
    handler I'd just do
    ctx.waitUntil(this.fetch())
    in your
    scheduled
    handler
  • c

    C o m f i i

    04/20/2023, 7:44 PM
    dope thanks to both answers ^
  • f

    ForwardMotion

    04/20/2023, 11:27 PM
    is it possible, to have an email worker recive an email, then to have that email displayed on a cloudflare page? I haven't worked with workers before and im not sure how or if diffent parts of them can interact like that?
  • a

    amorfati

    04/21/2023, 2:19 AM
    awesome
  • z

    zegevlier

    04/21/2023, 5:35 AM
    On a page behind Cloudflare? Sure! You can use the email worker to store it to something like KV, R2 or D1, then fetch it from there again to display it on a webpage. If you mean displaying it on the CF dashboard, then no, that's not currently implemented and I'm not aware of any plans for that.
  • f

    ForwardMotion

    04/21/2023, 5:53 AM
    yes to a webpage, where i am struggling is how to get the email worker to upload to the R2 bucket
  • z

    zegevlier

    04/21/2023, 5:55 AM
    Where in that are you stuck?
  • f

    ForwardMotion

    04/21/2023, 6:03 AM
    okay so first how to get the content of the email, i think its like this
    message.headers.get('subject')
    or
    message.headers.get('body')
  • f

    ForwardMotion

    04/21/2023, 6:05 AM
    now im just lost at how to upload that to R2
  • f

    ForwardMotion

    04/21/2023, 6:07 AM
    okay so in this
    Copy code
    export default {
      async fetch(request, env) {
        const url = new URL(request.url);
        const key = url.pathname.slice(1);
    
        switch (request.method) {
          case 'PUT':
            await env.MY_BUCKET.put(key, request.body);
            return new Response(`Put ${key} successfully!`);
  • f

    ForwardMotion

    04/21/2023, 6:07 AM
    i don't under stand this line
    Copy code
    const key = url.pathname.slice(1);
  • f

    ForwardMotion

    04/21/2023, 6:09 AM
    thats from r2 docs.
  • s

    Skye

    04/21/2023, 6:16 AM
    URL.pathname is a string, such as
    /my-path-here
    . You don't want to include that initial slash, so you use
    .slice(1)
    to make it just
    my-path-here
    🙂
  • f

    ForwardMotion

    04/21/2023, 6:16 AM
    ahh okay so "key" is the path of the upload?
  • f

    ForwardMotion

    04/21/2023, 6:19 AM
    how do i authenticate to put into the bucket?
  • s

    Skye

    04/21/2023, 6:31 AM
    Correct
  • s

    Skye

    04/21/2023, 6:32 AM
    What do you mean by this - authenticating users? If so, there are lots of ways to do this, you could check the headers in your worker, you could use firewall rules, cloudflare access, etc. If you mean your worker authenticating to R2, there's no need for that, it's handled automatically
  • f

    ForwardMotion

    04/21/2023, 6:33 AM
    yes ment the worker, figured since no docs mentioned auth it was just handled.
  • s

    Skye

    04/21/2023, 6:34 AM
    Yep, it's all done through cloudflare magic 😅
  • f

    ForwardMotion

    04/21/2023, 6:35 AM
    yea lot of magic I am far from understanding lol
  • s

    Skye

    04/21/2023, 6:39 AM
    So is everyone when they first start! We're here to help you work out the problems you encounter, feel free to ask whenever you need it
  • f

    ForwardMotion

    04/21/2023, 6:47 AM
    okay can you tell me where i am going wrong?
    Copy code
    export default {
      async email(message, env, ctx) {
        const key = message.headers.get('subject')
        const msg_body = message.headers.get('body')
    
        await NAME_OF_MY_BUCKET.put(key, msg_body)
    
      }
    }
1...240624072408...2509Latest