https://discord.cloudflare.com logo
Join Discord
Powered by
# functions
  • s

    saibotsivad

    01/03/2022, 8:11 PM
    I don't care what the Stripe or CF team says, the Stripe SDK absolutely does not work with Pages, so yeah you've basically got to hit their API manually
  • e

    Erwin

    01/04/2022, 12:16 AM
    To get the Stripe SDK working on Workers, you have to bundle it with Webpack and polyfills for Node specific instances. But the challenge is that you don't have any bundling step in Pages Functions.. and Functions doesn't do automatic polyfilling yet.
  • f

    fidgetboy12321

    01/04/2022, 12:16 AM
    I am trying to do a POC CF pages app with some workers. Recently, I started attempting to use the fetch API to pull things from a 3rd party, but that only works locally (wrangler dev) but not when I deploy to CF pages. I can't find any docs on how to debug or look at logs. I tried wrangler tail but I don't know the "script name" in that case. Any advice? Code looks like this:
    Copy code
    import { getApiUrl, lookupQueryStringVariable } from "./utils";
    
    export const onRequestGet = async ({
      request,
      env,
      params,
      waitUntil,
      next,
      data,
    }) => {
      const gameId = lookupQueryStringVariable(request, "gameId");
      const url = `${getApiUrl()}game-state&gameId=${gameId}`;
      return fetch(url, {
        method: "GET",
        cache: "no-cache",
      });
    };
  • e

    Erwin

    01/04/2022, 12:16 AM
    Although I think @User was toying with the idea of including it in wrangler 2 I think?
  • e

    Erwin

    01/04/2022, 12:17 AM
    Hehe.. I was just typing to see if you could include the code snippet @User 🙂
  • f

    fidgetboy12321

    01/04/2022, 12:18 AM
    right now i am getting a
    Error 1101
    and just trying to figure out how to debug or look at logs of some kind
  • e

    Erwin

    01/04/2022, 12:23 AM
    As mentioned in the Workers channel.. are you by any chance trying to connect from a custom domain to an endpoint in the same zone?
  • f

    fidgetboy12321

    01/04/2022, 12:36 AM
    nope just trying to connect to a site on the regular internet...although i guess that site is managed by CF. not sure if that matters.
  • f

    fidgetboy12321

    01/04/2022, 12:36 AM
    and i'm not doing any custom domain
  • e

    Erwin

    01/04/2022, 12:42 AM
    Nope.. it only matters if you are trying to connect from your own worker to another worker that is running on the same zone..
  • f

    fidgetboy12321

    01/04/2022, 12:55 AM
    perhaps what i can do is try to isolate the problem and just post the actual repo here
  • e

    Erwin

    01/04/2022, 12:58 AM
    Yeah.. the only thing I can think of is the destructuring the argument.. It could be there is some difference between say Miniflare and the workers runtime on how they deal with destructuring
    undefined
    values? Can you remove all unused ones?
  • s

    saibotsivad

    01/04/2022, 2:35 AM
    I know Pages won't work because of the bundling problem, but I couldn't ever get it to work in Workers with Wrangler using webpack, a la this (still opened and generally undiscussed) issue which I also ran into: https://github.com/stripe-samples/stripe-node-cloudflare-worker-template/issues/2
  • s

    saibotsivad

    01/04/2022, 2:36 AM
    I ended up writing my own simple "sdk" (just some helper code wrapping `fetch`and calling the Stripe API directly) because I couldn't get their SDK to bundle with webpack any way that I tried it
  • e

    Erwin

    01/04/2022, 2:38 AM
    Yeah, I haven’t tried to get it running at all, but was trying to point out that it certainly won’t work in Pages yet.
  • s

    saibotsivad

    01/04/2022, 2:39 AM
    right right, I hear ya
  • s

    saibotsivad

    01/04/2022, 2:40 AM
    I certainly don't know the answer, but I've wondered if there could be a way to denote "for this npm module use the CF authorized polyfills"
  • e

    Erwin

    01/04/2022, 2:40 AM
    That is basically what we are considering for wrangler2 if I understood it correctly.
  • s

    saibotsivad

    01/04/2022, 2:41 AM
    that makes sense
  • s

    saibotsivad

    01/04/2022, 2:42 AM
    it's a big commitment to say "we'll support a polyfill version of some third party sdk" so I definitely would rather push back and have the third party (in this case Stripe) update their libs to support a Worker environment, but I understand that's hard as well 🤷‍♂️
  • s

    saibotsivad

    01/04/2022, 2:43 AM
    (because people like me complain haha)
  • m

    maximillian

    01/04/2022, 12:32 PM
    I'm trying to write tests for my functions, but it seems like the
    Response.redirect
    isn't defined. What am I missing?
  • m

    maximillian

    01/04/2022, 12:34 PM
    My function works in wrangler, but when I try to write automated tests in jest the
    Response
    object doesn't seem to have this static method. I've tried both testEnvironment:
    jsdom
    and
    node
    , as well as replacing fetch with
    isomorphic-fetch
  • f

    fidgetboy12321

    01/04/2022, 9:03 PM
    i'm looking for some guidance in how to use the fetch api within workers that are deployed via Cloudflare Pages. I have broken down my failing case to a simple vanilla javascript example here: https://cloudflarepageswithworkersandfetchapi.pages.dev/
  • f

    fidgetboy12321

    01/04/2022, 9:04 PM
    the way i'm doing the fetch is here: https://github.com/AndrewLane/CloudflarePagesWithWorkersAndFetchApi/blob/main/functions/use-fetch.js
  • f

    fidgetboy12321

    01/04/2022, 9:04 PM
    any guidance?
  • w

    Walshy | Pages

    01/04/2022, 9:09 PM
    Your function is throwing an exception
  • w

    Walshy | Pages

    01/04/2022, 9:09 PM
    Which would explain why it doesn't work
  • f

    fidgetboy12321

    01/04/2022, 9:10 PM
    yeah, but why does it work on localhost via miniflare? i know there's probably a silly mistake somewhere, but i can't figure out how to debug or see logs or anything.
  • s

    steranevdy

    01/05/2022, 12:12 PM
    is there a way to view function metrics like what you have in workers dashboard?
1...535455...392Latest