React + Vite + Page Functions

How do I get the ability to use vite along with page functions locally with wrangler? Currently I am running this script: "wrangler pages dev --port=8080 --proxy=3000 --compatibility-date=2023-05-18 -- bunx --bun vite" and the vite server boots up and I can access localhost:3000 fine. But when I try to do a get request for localhost:3000/api/create-checkout-session I just get an empty page and not my api. Not sure how to configure it so the function is served correctly. Any ideas would be super helpful!
5 Replies
Hello, I’m Allie!
What do your Functions look like?
boywonder350
boywonder350OP15mo ago
No description
No description
boywonder350
boywonder350OP15mo ago
This is how I have my project folder structure set up I notice if I access localhost:8080/api/create-checkout-session then it works correctly, but if I do localhost:3000/... then it does not. Ideally in my react component I would just have fetch("/api/create-checkout-session", ...) but I am not sure it will work? I appreciate the help @HardAtWork 🙂
Hello, I’m Allie!
If wrangler is running on port 8080, then you should be accesing your site from there too. Then it should just work Should have seen that above Basically, Vite(and the port it runs on, 3000) should only ever be accessed by Wrangler, not by you
boywonder350
boywonder350OP15mo ago
oh!! Amazing, that makes a lot more sense works like a charm now 😄
Want results from more Discord servers?
Add your server