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

    AA

    04/26/2023, 11:53 AM
    anyone recommend a decent doc for setting up your projects for workers? making a number of webhooks. should this be a single git repo etc?
  • h

    HardAtWork

    04/26/2023, 11:56 AM
    Yes, a single repo should be more than enough to handle a handful of webhooks.
  • a

    AA

    04/26/2023, 12:09 PM
    I know pages doesn't like multiple things in same repo, so I thought I'd ask
  • l

    Lloyd

    04/26/2023, 12:13 PM
    Can Page functions rewrite and modify the html like Workers can? https://developers.cloudflare.com/workers/examples/rewrite-links/ So a user visits, and the Pages function modifies the response?
  • l

    Lloyd

    04/26/2023, 12:13 PM
    Or are Pages functions only manually called by some client side code?
  • k

    kian

    04/26/2023, 12:35 PM
    Yes
  • l

    Lloyd

    04/26/2023, 1:19 PM
    Is there an example of that? 🙂
  • f

    frankjonen

    04/26/2023, 1:23 PM
    Being new on the platform, the emphasis on the size limit and that the example isn’t even mentioned. Contact forms would be the most obvious use. I figured might be a reason why that topic is avoided.
  • s

    Skye

    04/26/2023, 1:25 PM
    You can use it for receiving of any emails 🤷‍♀️
  • h

    HardAtWork

    04/26/2023, 1:25 PM
    I don't think so, explicitly, but the nice thing about Functions is that, generally, code that works on Workers also works on Functions.
  • e

    embed

    04/26/2023, 2:40 PM
    Does anyone know if Cloudflare has any problems with other CDNs? I am using a different CDN for storing files but when I try to fetch them on my workers they respond with a "Too Many Redirects." Contacted the CDN and they said that they see the requests from Cloudflare and that they are processing normally, so it seems to be on Cloudflare's side. edit: Fixed, seems Cloudflare wasn't happy with the forced HTTPS on the CDN. I turned it off and it works now.
  • s

    sathoro

    04/26/2023, 3:49 PM
  • e

    embed

    04/26/2023, 3:50 PM
    1312
  • d

    Dani Foldi

    04/26/2023, 4:43 PM
    While this isn’t related to #779390076219686943, set your SSL to Full to avoid the forced redirect loop
  • e

    embed

    04/26/2023, 4:44 PM
    I wasn't sure where to put it as I was only having the problem on CF Workers, locally it worked fine.
  • f

    frankjonen

    04/26/2023, 4:46 PM
    Is there a documentation to this documentation? https://developers.cloudflare.com/workers/runtime-apis/email-event/#emailmessage-definition
  • c

    Chaika

    04/26/2023, 5:03 PM
    What are you looking for? Email Worker docs live mostly over here, other then the types: https://developers.cloudflare.com/email-routing/email-workers/
  • f

    frankjonen

    04/26/2023, 5:15 PM
    OK that looks different, more complete. Based on the other docs I guessed that code together and… well it doesn't do much of anything.
    Copy code
    javascript
    /**
     * POST /api/send
     */
    export async function onRequestPost(context) {
      try {
        let input = await context.request.formData();
        let email = "<EMAIL ADDRESS>"; // replace with your email address
        let pretty = JSON.stringify([...input], null, 2);
    
        // trigger email event with form data as message
        let emailEvent = new CustomEvent("email", {
          detail: {
            message: pretty
          }
        });
        dispatchEvent(emailEvent);
    
        // create HTML template with JSON data
        let html = `
          <html>
            <head>
              <title>Form data has been sent successfully</title>
            </head>
            <body>
              <pre>${pretty}</pre>
            </body>
          </html>
        `;
    
        return new Response(html, {
          headers: {
            'Content-Type': 'text/html',
          },
        });
      } catch (err) {
        return new Response('Error processing form data', { status: 400 });
      }
    }
  • c

    Chaika

    04/26/2023, 5:17 PM
    What are you trying to do? The types you highlighted are for email workers receiving emails You can use workers to send email out: https://developers.cloudflare.com/email-routing/email-workers/send-email-workers/ But that's not supported in Pages yet I imagine If you want a contact form, I would look into Mailchannels, they have a partnership with CF that lets you use them from Workers for free, and there's a pages plugin for them as well: https://developers.cloudflare.com/pages/platform/functions/plugins/mailchannels/
  • f

    frankjonen

    04/26/2023, 5:19 PM
    Guess I'll have to try again with Mailchannels then. Last time I couldn't get it to work.
  • c

    Chaika

    04/26/2023, 5:20 PM
    Did you get a specific error or anything? Make sure to set up SPF/DKIM, which are in that guide
  • f

    frankjonen

    04/26/2023, 5:21 PM
    Just that nothing happened. No errors either. I'll take a look at the records setup then. Maybe that was the issue.
  • c

    Chaika

    04/26/2023, 5:22 PM
    (you don't have to use the plugin, you can manually send an email using fetch as well: https://support.mailchannels.com/hc/en-us/articles/4565898358413-Sending-Email-from-Cloudflare-Workers-using-MailChannels-Send-API)
  • s

    switz

    04/26/2023, 5:40 PM
    is this a bad reason to use workers? seems like it's exorbitantly expensive to front a website just to add this header:
    Copy code
    addEventListener("fetch", event => {
      event.respondWith(handleRequest(event.request))
    })
    
    async function handleRequest(request) {
      const requestWithRegion = new Request(request);
      
      if (request.cf?.timezone) {
        requestWithRegion.headers.set('x-timezone', request.cf?.timezone);
      }
    
      return fetch(requestWithRegion);
    }
    namely the duration would add up very quickly (80gb-s for just 2k requests?)
  • h

    HardAtWork

    04/26/2023, 5:45 PM
    Note that running in Bundled mode would mean you can ignore the Duration there.
  • s

    switz

    04/26/2023, 5:46 PM
    ah interesting, good point
  • c

    Chaika

    04/26/2023, 5:52 PM
    Workers work well for glue like that. It doesn't look like timezone is in a ruleset engine field, otherwise I would say to use Transform rules add request header if you could. Bundled is $0.50 / million, I don't think that's really exorbitantly expensive
  • h

    HardAtWork

    04/26/2023, 5:52 PM
    Would be nice if this was supported by a Request Header rewrite, but it appears that GeoIP timezones aren't a part of Rules Engine.
  • s

    switz

    04/26/2023, 6:38 PM
    yeah def reasonably cheap if you're using bundled
  • s

    switz

    04/26/2023, 6:38 PM
    thanks all!
1...241824192420...2509Latest