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

    Cоlе

    12/23/2021, 10:23 PM
    @User
    .sign()
    takes in a Uint8Array, as opposed to a string. You'll want something like this:
    Copy code
    js
    .sign(new TextEncoder().encode(env.JWT_PRIVATE_KEY));
  • s

    Skye

    12/24/2021, 3:53 AM
    is it okay to use functions as an easier way to deploy a worker from a repo on every commit? (i.e. no actual page)
  • s

    sandeepsihari

    12/24/2021, 4:44 AM
    @User by doing so now i am getting another error.
    TypeError: Key must be of type CryptoKey. Received an instance of Uint8Array
  • c

    Cоlе

    12/24/2021, 5:43 AM
    You're using https://github.com/panva/jose ?
  • c

    Cоlе

    12/24/2021, 5:46 AM
    Yea sure. And if you use a
    _worker.js
    it's basically identical to workers, but compiled using pages
  • s

    sandeepsihari

    12/24/2021, 7:19 AM
    yes
  • c

    Cоlе

    12/24/2021, 7:34 AM
    Oh my bad. You're using JWT, I was looking at JWS. I can have another look tomorrow morning.
  • c

    Cоlе

    12/24/2021, 7:34 AM
    https://github.com/panva/jose/blob/de36ecec530245d0b9a0eee96d5e9780e3884dd5/docs/classes/jwt_sign.SignJWT.md#sign looks like it should be the same, I'll have to have a look
  • s

    sandeepsihari

    12/24/2021, 5:04 PM
    Hey man i got it working with your solution the trick was to use a symmetric algorithm to sign the token like
    HS256
    otherwise i will need private key for signing and public key for the verification.
    Copy code
    token = await new jose.SignJWT({ phone: phone })
                .setProtectedHeader({ alg: "HS256" })
                .setIssuedAt()
                .setIssuer(JWT_ISSUER)
                .setAudience(JWT_AUDIENCE)
                .setExpirationTime(JWT_EXPIRATION_TIME)
                .sign(new TextEncoder("utf-8").encode(secret key));
  • r

    Rhino233

    12/25/2021, 7:18 PM
    Hi, does anyone have a working example of SSR of react using pages/functions?
  • e

    Erwin

    12/26/2021, 11:58 PM
    I don’t have a working sample, but one trick from the days I did get SSR working on Cloudflare Workers-like environment was to import the browser version of the SSR component. That one doesn’t use NodeJS specific streams. Then do the renderToString thing on your main component and off you go. If you don’t have to do any data loading that is. If you need to do that too, it gets to be a bit more complicated and depends very much on what libraries you use for say routing and data storage.
  • r

    Rhino233

    12/27/2021, 5:21 AM
    thx for reply, I got it work to retrieve some data from backend server and dynamically generate html from it, good enough for me now. The only problem is "functions" doesn't have paid plan, and we have visits far more than the free quota 100k requests.
  • w

    wonkrattle

    12/27/2021, 5:23 AM
    Isn’t it just priced like workers?
  • w

    wonkrattle

    12/27/2021, 5:24 AM
  • e

    Erisa | Support Engineer

    12/27/2021, 5:26 AM
    Not while its in Beta, when it hits GA or later in beta it will be changed to Workers pricing
  • e

    Erisa | Support Engineer

    12/27/2021, 5:27 AM
    You can apply for an increased beta quota by checking out the form in the pinned message here (https://docs.google.com/forms/d/e/1FAIpQLSe4N0BjIxu9AuissCAtYjXUovViXmdx2zopjzASaJi_SImJsw/viewform?usp=send_form) As long as you have a valid use-case they should be willing to. Though it is still beta and not worth putting production-critical stuff through just yet
  • e

    Erwin

    12/27/2021, 5:47 AM
    There is the form to fill out while they are still in beta. Let me know if you can’t find it. They would be happy to up it for you I am sure.
  • e

    Erwin

    12/27/2021, 5:47 AM
    Oh.. @Erisa | Support Engineer obviously beat me to it.. nvm me 😂
  • r

    Rhino233

    12/27/2021, 6:24 AM
    Yeah, already submit a form from company account, thx!
  • e

    Erwin

    12/27/2021, 8:56 AM
    With the holidays that might actually take a bit longer than it usually would 😄
  • m

    Matt

    12/28/2021, 1:16 AM
    Will it ultimately be abolished?
  • j

    James

    12/28/2021, 1:18 AM
    That is the plan, yes. Greg spoke about this a little while ago in the channel: https://discord.com/channels/595317990191398933/910978223968518144/921921026349207562
  • d

    Deleted User

    12/31/2021, 11:08 AM
    Hello! Would I be able to build an API with Cloudflare Pages functions, if so, is there an example repository I can see?
  • b

    Beny

    12/31/2021, 11:24 AM
    Pages Functions are built on Workers, so whatever you can do in Workers you can do in Pages 🙂 There's a tutorial of how to build an image sharing website on Pages here https://blog.cloudflare.com/building-full-stack-with-pages/
  • d

    Deleted User

    12/31/2021, 11:33 AM
    I understand that, but most of the time I use functions it says that nothing exists. I also don't know how to use Workers that well.
  • b

    Beny

    12/31/2021, 11:34 AM
    What do you mean by nothing exists?
  • d

    dfcowell

    01/01/2022, 6:37 AM
    Just ran into something weird. I'm using Pages Functions, but I have a hunch that this applies to the Workers platform more broadly. Is it intentional that
    fetch
    requests made from a function don't include a user-agent header? I built a function that consumes the Github API. It works locally with
    wrangler pages dev
    , but when running on Cloudflare calls to Github fail with this error:
    Request forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.
    One way or another, something should change - either Wrangler should not send a UA header when running locally (so it matches the Workers behaviour) or Workers should send a UA header. Not sure what the expected behaviour is here. 🙂
  • e

    Erwin

    01/01/2022, 7:45 AM
    Workers will not set a UA by default, but when you say it worked with wrangler dev, do you mean locally with Miniflare? Because wrangler dev and regular workers are running the exact same runtime. With wrangler dev you basically deploy a one-off script.
  • d

    dfcowell

    01/01/2022, 8:01 AM
    Yes, I mean locally with Miniflare, sorry, I could have been more clear about that.
  • d

    dfcowell

    01/01/2022, 8:04 AM
    To avoid any ambiguity, this is the command I'm running where it works without me manually setting a UA (and I assume a UA header is sent!) Running the exact same code (by pushing to the repo and deploying the Pages site) results in the fetch request failing with the Github API error above in production.
    Copy code
    dotenv -- cross-var npx wrangler@pages pages dev -k GITHUB -b GITHUB_CLIENT_ID=%GITHUB_CLIENT_ID% -b GITHUB_CLIENT_SECRET=%GITHUB_CLIENT_SECRET% -- npm run start
1...495051...392Latest