In your Framework. Then when you run the

In your Framework. Then when you run the build command, it builds your Functions for you
12 Replies
lj
ljā€¢3mo ago
SPA->fetch->Functions{kv=islocal?getPlatform:context.env}->response to SPA ? I already have the context.env in Functions, what's the getPlatform use for? Is that means if I'm not the framework developer, it's no use for me?
Hard@Work
Hard@Workā€¢3mo ago
Wait, so what is your setup? Are you using a framework, or just straight Vite?
lj
ljā€¢3mo ago
I use react+vite+tailwinds to generate SPA. Now I want let it save something. When I use vite dev the SPA works ok but the Functions can't work. The Function work depends on the wrangler pages dev. What if vite can do this? I found this https://github.com/TorchAuth/vite-plugin-wrangler-spa, but it's not work good. The final target is use one server that can use bindings local and hot reload from React source file changed. getPlatformProxy is used by 'who serve the front end'? That means vite should do this but not wrangler? This plugin allows both the React SPA and Cloudflare functions to run with LiveReload locally, and at the same time. This solves a major pain point that currently exists, where you cannot work locally with LiveReload for the React project, you are forced to use preview. This plugin allows both the React SPA and Cloudflare functions to run with LiveReload locally, and at the same time. when use --proxy is a good way that wrangler handle the Functions and vite provide the assets. But that's gone.
Hard@Work
Hard@Workā€¢3mo ago
getPlatformProxy is really made to be used by your framework, which doesn't help much if you aren't actually using one Let me see if there is a recommendation for cases like yours...
lj
ljā€¢3mo ago
Thanks! https://github.com/TorchAuth/vite-plugin-wrangler-spa is realy fine for me. But there throw an error from wrangler.šŸ˜†
GitHub
GitHub - TorchAuth/vite-plugin-wrangler-spa: Vite plugin that allow...
Vite plugin that allows for simultaneous Cloudflare Page Functions and static SPA development locally - TorchAuth/vite-plugin-wrangler-spa
Hard@Work
Hard@Workā€¢3mo ago
Ok, got it. Current advice is to run wrangler pages dev in one terminal, and vite dev in the other, then in dev fetch the pages dev port for functions calls
lj
ljā€¢3mo ago
Yes. It sounds good. Will the develop way comes better?šŸ˜† I'm studying remix now. Maybe that's a good way. Thanks for explain!
Hard@Work
Hard@Workā€¢3mo ago
Actually, the person I was speaking to just passed along this: https://www.npmjs.com/package/wrangler-pages-functions-dev
npm
wrangler-pages-functions-dev
A vite plugin for handling pages functions requests in local dev mode. Latest version: 0.0.7, last published: 3 months ago. Start using wrangler-pages-functions-dev in your project by running npm i wrangler-pages-functions-dev. There are no other projects in the npm registry using wrangler-pages-functions-dev.
Hard@Work
Hard@Workā€¢3mo ago
It's not an official thing or anything But should work as a bodge
lj
ljā€¢3mo ago
That just do what you said. Auto proxy the request redirect to wrangler. I'll try it now. Thanks! That means some trans the proxy function from wrangler to vite:lul: wrangler pages dev --proxy [vite_url] ==> vite --prxoy [wrangler_url]belike :dogekek: Who's the boss:dogekek:
Hard@Work
Hard@Workā€¢3mo ago
The above package shouldn't need a --proxy command?
lj
ljā€¢3mo ago
Yes, I'm just making an analogy. It's actruly in vite.config. To get closer to the truth, he got it from the result after wrangler was executed This is the essence of this matter.
Want results from more Discord servers?
Add your server