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

    YN

    05/24/2023, 7:00 AM
    No, I would like to use Browser Rendering only. I knew that security issues are there for fetch API.
  • d

    divby0

    05/24/2023, 8:25 AM
    What would be the best approach to return one answer for a request immediately and then after an external api has answered return another answer? Without workers, I'd probably use server-sent-events + an event emitter but I am not sure that this is the serverless way
  • r

    Razvan

    05/24/2023, 8:53 AM
    someone know what is this?

    https://cdn.discordapp.com/attachments/779390076219686943/1110852947421712444/image.png▾

  • c

    Cyb3r-Jok3

    05/24/2023, 11:14 AM
    I mean depends on what your API server needs to do. If simple requests handling then sure
  • b

    banbanboi

    05/24/2023, 12:32 PM
    how to fix cors issue when consuming the worker url? it works in a plain get, but if i include a header key value in the request, it throws the Cors error. i also provided the correct cors response

    https://cdn.discordapp.com/attachments/779390076219686943/1110908261160460391/image.png▾

  • h

    HardAtWork

    05/24/2023, 12:34 PM
    Do you also return CORS headers on
    OPTIONS
    requests?
  • b

    banbanboi

    05/24/2023, 12:35 PM
    no, for now I only use Get, post
  • h

    HardAtWork

    05/24/2023, 12:35 PM
    That might be why. Your browser may be sending a preflight
    OPTIONS
    request, which fails.
  • b

    banbanboi

    05/24/2023, 12:38 PM
    i removed it including the Head, but still the same Here's what my Web looks like when calling the worker url

    https://cdn.discordapp.com/attachments/779390076219686943/1110909744136343552/image.png▾

  • h

    HardAtWork

    05/24/2023, 12:39 PM
    No, I mean that your browser itself is sending an
    OPTIONS
    request, irrespective of your
    Access-Control-Allow-Methods
    . If you don't handle that in your Worker, then the entire thing fails
  • b

    banbanboi

    05/24/2023, 12:41 PM
    no options sent by the browser
  • b

    banbanboi

    05/24/2023, 12:41 PM
    during request
  • l

    Liberator

    05/24/2023, 12:54 PM
    I was thinking about using Workers to build an API for a timetabling app that will have to use a sort of DB. I've seen a guide on using Workers with Fauna DB, but I'm not sure if this is good for scalability. Any thoughts?
  • b

    BenParr

    05/24/2023, 12:57 PM
    Hi all, I am getting some extremely weird behaviour.....
    Copy code
    echo "${{ parameters.cfAccessClientId }}" | npx wrangler secret put cfAccessClientId
                      echo "${{ parameters.cfAccessClientSecret }}" | npx wrangler secret put cfAccessClientSecret
    if I set secrets like this, I can return them in response and they show... But I am not able to use them in a request to bypass cloudflare zero trust.... however if I set them as env variables when deploying like this
    Copy code
    npx wrangler deploy `
                        --var cfAccessClientId:"${{ parameters.cfAccessClientId }}" `
                        --var cfAccessClientSecret:"${{ parameters.cfAccessClientSecret }}"
    it works absolutely fine...... how is this possible??
  • b

    BenParr

    05/24/2023, 1:03 PM
    Also to add I am accessing both through env. Assuming this is the correct way for both?:
  • c

    Cyb3r-Jok3

    05/24/2023, 1:35 PM
    Workers scale very easily not sure about Fauna DB but if it does then it should be good
  • l

    Liberator

    05/24/2023, 1:52 PM
    What about GraphQL, does that work with Workers?
  • c

    Cyb3r-Jok3

    05/24/2023, 2:06 PM
    https://github.com/cloudflare/workers-graphql-server
  • l

    Liberator

    05/24/2023, 2:07 PM
    Seems good, thanks
  • b

    BenParr

    05/24/2023, 2:08 PM
    I decided to send the secret to a test webhook on webhook.site, here I realised
    \ufeff
    was being added to the front. No idea why tho
  • i

    IdkWhatever69

    05/24/2023, 2:50 PM
    am i doing something wrong?

    https://cdn.discordapp.com/attachments/779390076219686943/1110942956573175818/Screenshot_2023-05-24_at_8.20.14_PM.png▾

  • i

    IdkWhatever69

    05/24/2023, 2:50 PM
    cron triggers dont work
  • i

    IdkWhatever69

    05/24/2023, 2:51 PM

    https://cdn.discordapp.com/attachments/779390076219686943/1110943112668401796/Screenshot_2023-05-24_at_8.21.09_PM.png▾

  • s

    sathoro

    05/24/2023, 2:52 PM
    if you are doing a CORS request, your browser is automatically sending an OPTIONS request
  • s

    sathoro

    05/24/2023, 2:53 PM
    Workers is only for "simple requests"? 🙂
  • i

    IdkWhatever69

    05/24/2023, 3:08 PM
    anyone? please help 🥲
  • b

    banbanboi

    05/24/2023, 3:08 PM
    so having a key value request header will not work? i put the worker key value in querystring, does this workaround is the best practice ? does jwt will also work or I will be having a CORS issue once I implement it?
  • s

    sathoro

    05/24/2023, 3:08 PM
    you just need to implement CORS correctly. you aren't even handling the CORS preflight request so of course it won't work
  • s

    sathoro

    05/24/2023, 3:11 PM
    personally I call this function on all responses before returning them to the client:
    Copy code
    js
    const enableCORS = (request, response) => {
      const origin = request.headers.get("origin") || "";
    
      const isAllowedOrigin =
        origin === "http://localhost:3000" ||
        origin.endsWith(".example.com");
    
      if (isAllowedOrigin) {
        for (const [key, value] of Object.entries({
          "Access-Control-Allow-Origin": origin,
          "Access-Control-Allow-Methods": "POST, DELETE, GET, OPTIONS",
          "Access-Control-Allow-Headers": "*",
        })) {
          response.headers.append(key, value);
        }
      }
    
      return response;
    };
    and in my route handling I have a simple
    Copy code
    js
    if (request.method === "OPTIONS") {
      return new Response("ok");
    }
    and this is what ties it together...
    Copy code
    js
    const response = await handleRequest(request, env, context, sentry);
    
    return enableCORS(request, response);
  • b

    banbanboi

    05/24/2023, 3:14 PM
    thank you can I try this ?
1...248924902491...2509Latest