I'm having trouble with nested routes in page functions... my understanding is that a file at `funct

I'm having trouble with nested routes in page functions... my understanding is that a file at functions/users/friends/index.ts will serve a request to /users/daniel/friends, in theory displaying a list of all the friends of daniel, but Im just getting the root app page instead of function output. Do I need to just use a [[catchall]].ts file at functions/users/[[catchall]].ts and handle all of the logic there, or am I doing something wrong?
17 Replies
omg_ketchup
omg_ketchupOP3mo ago
To add a little context- my functions/users/index.ts file is working properly, and so is my functions/users/[user].ts file- index displays a list of users, and [user] displays the individual user matching the route param.
Andrei
Andrei3mo ago
Hey again! Could you please look at my case or is there a better place to file an issue? Really don't want it to get lost. Appreciate it.
Walshy
Walshy3mo ago
I can't do too much without a url to test, if I have that I can trace and figure out the timings. But best is to have a thread in #pages-help - free flowing channels are hard to not get lost in
juanferreras
juanferreras3mo ago
hey Andrei – I sent a DM with some steps I've taken recently successfully. In short feel free to create an /api OR function that returns immediately without any data fetching and one that does data fetching to compare. If the former's great and the latter isn't – see if enabling Smart Placement and re-deploying helps (issue a few requests). In a small project of mine (D1 as database) that decreases end-user TTFB from ~700ms to ~250ms (depends on where you are, where your database is, etc.). I can't speak to the accuracy of timestamps (on whether the attribution of "after" the worker is finished is right/wrong) – the security protection on Workers to only advance on I/O has confused me in the past. For example, worker startup time inflated the first I/O operation when profiling with performance.now() when in reality it wasn't related to it but actually happened before it might be helpful to look at https://developers.cloudflare.com/pages/tutorials/localize-a-website/
omg_ketchup
omg_ketchupOP3mo ago
Does it make sense to have a separate package.json for the functions folder? Can I treat it as essentially a separate Typescript project within the root Pages project? I'm thinking about how to structure it so my functions can use stuff like database/ORM/backend packages without including them in the frontend project. I don't see any best practices on achieving this, although it does say to create a separate tsconfig.ts within /functions, so I assume package.json and everything else would work the same way...? I guess I'm just asking if there's any gotchas in this approach.
akazwz
akazwz3mo ago
I saw now remix framework worker asserts support is using pages functions build --outdir build/worker. is this anyway to add queue or email entrypoint to it?
jfx
jfx3mo ago
hi, i'm using free tier cloudflare pages for a personal website and some basic serverless functions logic i've really liked the product, but i'd like to know how to store logs for functions? currently i've been using real-time logging. via https://developers.cloudflare.com/pages/functions/debugging-and-logging/#limits seems they are not stored. looking for something similar to cloudwatch on AWS. do i need to pay for a cloudflare service? ah it looks like workers has this functionality, and may be better suited for me after reading https://developers.cloudflare.com/workers/static-assets/compatibility-matrix/
omg_ketchup
omg_ketchupOP3mo ago
So I've gotten most of my stuff working, but now I'm trying to hit a POST endpoint during local dev, and getting a 405 Method Not Allowed response. I've googled extensively, and most of the results are regarding deployed apps, and the function not being available. How can I resolve this locally? My GET endpoints are working properly, but not POST. I've added access-control-allow-methods headers, I've moved the target file into a different folder, I've tested different data, I'm getting the same result from my React app as I am in Postman... I'm not sure where else to look.
akashra
akashra3mo ago
Hm, I've got to look in to this further, but it seems all of my HTTP GET calls to a pages function sent with application/json are ending up cached and being seen as text/html by the time they pass through wrangler. Does this sound familiar?
Ricky U
Ricky U3mo ago
Do workers now support the native mongo driver?
tyteen4a03
tyteen4a033mo ago
What's the golden path for rate limiting on pages?
ab90..
ab90..3mo ago
How do you make sure your api endpoints aren't hit by just anyone? Is there a way to restrict them so my Cloudflare works are the only ones allowed to connect to my endpoints like api/foo
Sia
Sia3mo ago
Does anyone know if Pages Functions work with supabase.js? Essentially, does the runtime support supabase.js? Workers runtime does but don't know if they use the same runtime?
Hello, I’m Allie!
They use the use the same runtime
omg_ketchup
omg_ketchupOP3mo ago
I'm having trouble setting up vitest with Pages Functions. All the documentation is for Workers, and I'm trying to make it work, but... yeah. For example- I can't seem to get the "cloudflare:tests" imports to work. I'm also not sure about hitting endpoints- do I need to create a worker that replaces fetch and then use that? I thought that was a workers-only thing and wasn't necessary for Pages.
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Ricky U
Ricky U3mo ago
i created a function that redirects based on hostname, but how do i triger it to run on certain conditions, i.e. if a hostname does not match *mydomain.com then redirect...
Want results from more Discord servers?
Add your server