-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing Cloudflare Bindings locally #10389
Comments
Hey, currently it's only possible to use bindings after building. We should probably make that a bit more clear in the docs 🙏 |
I've created #10390 to clarify in the docs that you can use wrangler to test your local build. For everything else I believe this may be a duplicate of #4292 There is no perfect way to mock platform.env but it's possible for some things like kv, see this example: https://github.com/ghostdevv/short/blob/2d161720df6243c5ce4d107d90272c77fe13c14e/src/hooks.server.ts#L26 |
@ghostdevv Thank you for explaining it. I had doubts how does it work with bindings. So I should build sveltekit app locally like |
Off the top of my head you can use |
@ghostdevv Actually, your solution helped. With @miniflare packages, we can mock this functionality locally and even unit test. Finally, it all makes sense now. I can use SvelteKit app to build full stack app 😸 Thank you 🚀 |
@dinko-pehar , you are talking about Miniflare 2? DurableObjects is not possible to mock in dev mode. I've yet to seen a proper solution. |
Hi @gerhardcit |
|
Do you know if anything has changed with this? When vite rebuilds the app, wrangler doesn't seem to detect it and reload. I have to stop the server and start it up again. |
FWIW, CF intro'd Hyperdrive which let you connect your DB (currently only Postgres), e.g. Neon, without all the comm overhead, e.g. so no TCP handshake (1x), TLS negotiation (3x), and database authentication (3x). However and before I try to migrate my stuff, I wonder how the local dev story would be. I would need to setup a dev db at Neon (easy), connect it through Hyperdrive (should be easy) and use that remotely via a binding through local wrangler and SvelteKit (doubt that's easy and/or straight-forward). Wondering if I should enter this rabbit-hole... |
Had the same problem here. Did you find any way to asset this ? I looked in the documentation but there doesn't seem to be anything for that. |
Describe the bug
Hello.
I'm facing a problem which is related to Cloudflare Bindings when using SvelteKit. The documentation on bindings is rather vague.
There is a note at the end stating:
Assuming I'm on right track,
wrangler
can be used to serve SvelteKit in development locally as:It will proxy request to SvelteKit. However, to include the binding, I can use (for example KV):
I states :
But the problem raises when I try to access
platform.env
when it running. It states that platform is undefined.Reproduction
I've created a simple API endpoint.
In a fresh Sveltekit app, in
src/routes
add folder/kv
. In it, create a+server.js
with following code:Logs
System Info
Severity
serious, but I can work around it
Additional Information
I would like to use bindings when testing locally.
Also, Cloudflare Workers has good documentation on how to test using Jest your worker. It also works with bindings. I'm not sure how to use SvelteKit with this
unstable_dev
API.The text was updated successfully, but these errors were encountered: