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

    Rhino233

    01/22/2022, 8:34 PM
    was trying something dummy like to debug. Though I can see from cloudflare build section that functions rules are applied. but seems this function is not invoked
  • j

    James

    01/22/2022, 9:12 PM
    Unfortunately not yet, though I know it's definitely something that will be coming. I'd recommend sending logs to somewhere offsite for now, such as Honeycomb
  • v

    virgofx

    01/22/2022, 11:57 PM
    [QUESTION] The request headers
    context.request.headers
    in a Cloudflare Pages function is always an empty object
    {}
    . This is unfortunate as I'm trying to retrieve the User Agent as well as other headers sent by the client. I've
    JSON.stringify()
    the entire context object to see if it was there anywhere and could not find it. Any thoughts?
  • j

    James

    01/23/2022, 12:35 AM
    I'm pretty certain it's a
    Headers
    object, which will return
    {}
    when serialized. But if you try something like
    context.request.headers.forEach(console.log)
    you should see them all.
  • j

    James

    01/23/2022, 12:36 AM
    See https://developer.mozilla.org/en-US/docs/Web/API/Headers for more methods. You could also do
    headers.get('user-agent')
    for example
  • v

    virgofx

    01/23/2022, 12:36 AM
    OOh, let me unwrap it to a string and test
  • v

    virgofx

    01/23/2022, 1:06 AM
    @User That worked. Silly how I didn't think of that. Much appreciated.
  • j

    James

    01/23/2022, 1:07 AM
    Glad it worked!
  • j

    Jc

    01/23/2022, 8:05 PM
    does it make sense to use Functions to deploy a repo that is ONLY a function, and has no corresponding site?
  • j

    James

    01/23/2022, 8:09 PM
    You could, but a simple Worker may make more sense for something like that?
  • j

    James

    01/23/2022, 8:10 PM
    Pages Functions are essentially a more streamlined way to run Workers alongside your Pages project. If you just want to run a Worker, you can do that without Pages 🙂
  • j

    Jc

    01/23/2022, 8:20 PM
    gotcha - i guess i should point out that it does need to receive webhooks, so maybe it actually does have a site in some way, i'm also wanting to auto-deploy when merges to the production GitHub branch happen
  • z

    zsmooth

    01/23/2022, 8:27 PM
    You can receive a web hook with a straight worker trivially. The Pages auto-deploy is nice, but you could also set that up easily with a GitHub action. I’d probably stick with a Worker in your case.
  • j

    James

    01/23/2022, 8:28 PM
    Yeah agreed with @User. You can automate it with https://github.com/cloudflare/wrangler-action. Though if you do want to deploy an actual site with it in future, Pages will make the most sense then. 🙂
  • j

    Jc

    01/23/2022, 8:28 PM
    awesome - thanks to both, worker + action will be fine!
  • j

    James

    01/23/2022, 8:29 PM
    Pages Functions does bring along some nice magic like file-based routing though. Depending on the complexity, it may still make sense to use it, but for something like a simple webhook, I'd go for a basic Worker
  • i

    itsmatteomanf

    01/23/2022, 10:35 PM
    So... if I am depending on an API in the
    functions/
    folder and it's deployed at the same time as the project with the new changes, no way to fix that right? Any solution apart from double deploys?
  • g

    Greg Brimble | Cloudflare Pages

    01/23/2022, 11:31 PM
    Not quite following. No way to fix what? What does a double deploy do?
  • i

    itsmatteomanf

    01/23/2022, 11:31 PM
    Yeah, just realised I need to clarify.
  • i

    itsmatteomanf

    01/23/2022, 11:32 PM
    If the build page generation depends on the API it's being published with the build, I have no way to do that. I either have to deploy the API first and the then the build or retry the deployment to do basically the same.
  • g

    Greg Brimble | Cloudflare Pages

    01/23/2022, 11:33 PM
    Oh, funky. So you're using the API you've built in
    functions
    for some sort of static generation?
  • g

    Greg Brimble | Cloudflare Pages

    01/23/2022, 11:33 PM
    I guess you could simulate it in the build image?
  • i

    itsmatteomanf

    01/23/2022, 11:34 PM
    Yeah, it's running
    nuxt generate
    , and it's fetching the same API (as it would break the current version).
  • i

    itsmatteomanf

    01/23/2022, 11:34 PM
    I could, but it depends on KV/DOs...
  • g

    Greg Brimble | Cloudflare Pages

    01/23/2022, 11:34 PM
    I was just away to say...
  • g

    Greg Brimble | Cloudflare Pages

    01/23/2022, 11:35 PM
    Is this a common thing? Kinda Gatsby-ish.
  • g

    Greg Brimble | Cloudflare Pages

    01/23/2022, 11:36 PM
    Can you give an example? What's the benefit of doing this at build time over runtime?
  • i

    itsmatteomanf

    01/23/2022, 11:37 PM
    I feel like it is... It would basically require some sort of
    wrangler@beta pages dev
    thing within the build image. The fact that you can atomically deploy things together allows you to remove versioning in the internal API which is always a pain.
  • i

    itsmatteomanf

    01/23/2022, 11:39 PM
    For
    nuxt
    it's that the downloaded file is fully rendered, without additional JS files. For the specific call I'm doing it changes little as it's the data for a map which needs to be rendered on the client, but future calls will be different.
  • i

    itsmatteomanf

    01/23/2022, 11:40 PM
    It will not be realtime SSR, of course, but would work very well for SEO and speed.
1...676869...392Latest