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

    IEatBeans

    01/29/2023, 6:03 PM
    Ooohhhh, that’s perfect! Thanks!
  • s

    salutalice

    01/29/2023, 6:24 PM
    @James sorry I didn’t want to derail the topic. Producer does mean I can send a queue but not receive one and process it right ? I need another worker to process the queue
  • j

    James

    01/29/2023, 6:25 PM
    That's correct, yep
  • i

    IEatBeans

    01/29/2023, 8:37 PM
    Can you have middleware pass params to the next layer (could be another middleware or an endpoint?)
  • i

    IEatBeans

    01/29/2023, 8:51 PM
    Like if I have middleware for auth, and it decodes the jwt, I would like it to pass the decoded value onto the function running behind the middleware
  • j

    James

    01/29/2023, 8:51 PM
    I don't know if there's a "native" way, but you can manipulate
    context.data
    which will survive a request.
    context.data.auth = {}
    for example
  • i

    IEatBeans

    01/29/2023, 8:52 PM
    oh ok, that seems like a good solution
  • s

    salutalice

    01/29/2023, 8:53 PM
    context.data is exactly what you need. I do the same right now. James is right
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:19 AM
    Yup, that's the "native" way!
  • b

    bkyerv

    01/30/2023, 3:39 AM
    I am building an app using astro and functions. I got stuck with using cloudflare function on a ssr page that uses dynamic routes. On that page I need to access the
    id
    of the user from the url, use this id to fetch the user data and render it on the page. While I can access the url params via
    Astro.params
    in the frontmatter section I cannot use
    cloudflare functions
    in that section because it is executed on the server env. While I can use
    cloudflare functions
    inside the script tags (i.e. on the client) I cannot pass the url params that I have accessed from the frontmatter section to the script tag section. I was wondering has anyone come across similar situation and if there is any solution that could allow me access url params, use that info to fetch data using cloudlfare functions and render it on the page?
  • y

    Yudai Nakata

    01/30/2023, 4:25 AM
    Not sure if I correctly understand your problem, but isn't
    context.params
    in Pages Functions what you are after? https://developers.cloudflare.com/pages/platform/functions/routing/#dynamic-routes
  • b

    bkyerv

    01/30/2023, 7:38 AM
    Yeah, I understand that I can process request.url and access the parameters inside the function. Let me try to explain differently: On the client there is a list of items that when clicked render details of an item (say like a list of posts and when you click on any post URL section changes and details of that post are rendered on the screen) and I use SSR and dynamic routes on the client to implement all this. In order to render details of an item I need to fetch for such details. In order to fetch for details I need to access the URL section and grab the id of an item and pass it to fetch function. Since I am using SSR accessing the URL section, fetching details of an item and rendering html takes place on the server (This is not the same server environment where cloudflare functions are executed). All these happens on the client that is built using Astro. Unfortunately and if I understand it correctly request for endpoint that use cloudflare functions cannot be executed on the server and must be invoked on the client when javascript lands on the client/browser environment. This is why I cannot pass the URL section and
    id
    of an item that I have access to on the server side to the request for cloudflare functions that must be invoked on the client side.
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:04 PM
    > This is not the same server environment where cloudflare functions are executed Why? Do you have a separate server running somewhere? I think you might be misunderstanding something here. Within Functions, you could do all of: - grab the ID from the URL - fetch data from a datastore (e.g. KV, D1, or external sources using
    fetch
    ) - render some HTML with that data - return as a response
  • b

    bkyerv

    01/30/2023, 12:19 PM
    No I don't have any other separate server, I just assumed that those things are being executed in different places. Agreed, I think I am certainly confusing a lot of stuff here. In the interest of time I decided to go ahead with workers as I can fire requests against a worker in the frontmatter section of the astro project. Thank you for response
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:21 PM
    Cool! Glad you got it sorted! Yeah, in most situations, there are only two places code is executing (client/browser/device or server/serverless/edge/functions — the latter of which, is just Workers and it all runs together).
  • h

    HardAtWork

    01/30/2023, 12:23 PM
    Would be cool to see a "Hybrid" framework that mixes Server(Container maybe? For when the amount of requests/requirements necessitate a fully server), Edge, and Client-side Rendering.
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:24 PM
    That certainly would be interesting!
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:25 PM
    Frameworks are arguably "smart" today in splitting between client and edge, but I do think there's a little more they could probably be doing.
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:25 PM
    I'd be fascinated if one took that same idea to splitting three ways between server, edge and client.
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:25 PM
    Although, perhaps the more logical split would be data API, SSR'r and client.
  • h

    HardAtWork

    01/30/2023, 12:26 PM
    Actually, I think Vercel already does something sort of similar, with Next and Edge Functions? I don't remember if Edge Functions actually render things, but if they do, could be an interesting model.
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:27 PM
    Ah, true. Devs opt-in on a per-page basis whether the page can be rendered at the edge or if it needs the fuller environment (Lambda/Node.js).
  • h

    HardAtWork

    01/30/2023, 12:27 PM
    Because Workers/Functions are really powerful, but sometimes you need full Node/Deno support
  • h

    HardAtWork

    01/30/2023, 12:28 PM
    Without a bunch of Polyfills
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:28 PM
    nodejs_compat
    coming soon!
  • g

    Greg Brimble | Cloudflare Pages

    01/30/2023, 12:28 PM
    (But yeah, totally get you)
  • z

    zsmooth

    01/30/2023, 8:49 PM
    has anyone ran into not seeing any realtime logs from Pages functions (both through dashboard, and wrangler)? I'm running into that now and seem to remember there being a couple tricks to getting it to work if that happens, but it also might be Workers I'm thinking of... edit: never mind. wrangler was out of date. 😄
  • s

    Steve French

    01/31/2023, 7:26 PM
    is this true?
  • g

    Greg Brimble | Cloudflare Pages

    01/31/2023, 7:36 PM
    Yup! https://twitter.com/jasnell/status/1619451747277352960
  • s

    sudokar

    02/01/2023, 6:34 PM
    Hello, New to cloudflare pages. Can we have oauth style authN and authZ using functions. Do we need to use third party IDP for this feature. And also, is there a service which is equivalent to AWS API Gateway. Thanks.
1...341342343...392Latest