Skip to content
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

Not working on Cloudflare Workers #18

Closed
hanssonduck opened this issue Jul 15, 2022 · 7 comments
Closed

Not working on Cloudflare Workers #18

hanssonduck opened this issue Jul 15, 2022 · 7 comments

Comments

@hanssonduck
Copy link

It's not possible to run this when deployed on Cloudflare Workers. I'm getting the error global is not defined. Might have something to do with how the fetch workers there. Maybe this two repos could be of help to solve the problem.

https://github.com/esamattis/trpc-cloudflare-worker
https://github.com/valu-digital/npm-packages/tree/master/packages/trpc-fetch-api-adapter

@wobsoriano
Copy link
Owner

Need to polyfill the global object

@hanssonduck
Copy link
Author

Need to polyfill the global object

Thanks got it working using https://www.npmjs.com/package/@ungap/global-this.

Now I'm having another problem with CORS. The endpoint can be called directly (example /trpc/hello) but not with useAsyncQuery in a page. Is this a limitation of Workers or how should I add the correct headers for this?

Thank you for the help!

@hanssonduck
Copy link
Author

hanssonduck commented Jul 15, 2022

Actually I'm dumb.. the worker tried calling the localhost trpc server in production. Everything works now, thanks for the awesome Nuxt TRPC implementation!

@hanssonduck
Copy link
Author

hanssonduck commented Jul 16, 2022

@wobsoriano Do have time for another question regarding running on Cloudflare Workers?

It seems that using useAsyncQuery doesn't run on the server during SSR. Instead it runs on the client side and there is not data in the initial HTML sent from the server. Note that everything is working as expected when using the node preset.

@hanssonduck hanssonduck reopened this Jul 16, 2022
@hanssonduck
Copy link
Author

@wobsoriano hi, do you have any update on my second issue?

@wobsoriano
Copy link
Owner

Hey, just released v3. Probably fixes your issue @essarn

@hanssonduck
Copy link
Author

Yes it should work, looking forward to using the library with v10 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants