tsoa
tsoa copied to clipboard
Support Cloudflare Workers
Thanks for a great library. This is the first solutionen to keeping the model and the code in sync that I enjoy working with :)
I been slightly obsessed with cloudflare workers lately and would love using TSOA there. After going through the docs I came up with a solution that seems to be at least partly working: https://github.com/markusahlstrand/tsoa-workers, with a demo here: https://cloudworker-cms.sesamy-dev.workers.dev/docs
Would be interesting to see if anyone else would be interested in this approach and if it's in line with the plans for the TSOA project?
Sorting
-
I'm submitting a ...
- [ ] bug report
- [x] feature request
- [ ] support request
-
I confirm that I
- [x] used the search to make sure that a similar issue hasn't already been submit
Hello there markusahlstrand 👋
Thank you for opening your very first issue in this project.
We will try to get back to you as soon as we can.👀
I'd be happy to explore support for a CF Workers option. With https://github.com/lukeautry/tsoa/pull/1342, we also added additional customization possibilities for templates, which are targeted at these other runtime environments.
It looks interesting with the custom route generators. I'll have to have a look at that.
One thing that we needed to change to get it working with cloudflare was to break out the decorators to a separate package to avoid getting any node dependencies into cloudflare. Maybe this can be achieved some other way? The runtime works just fine in cloudflare so the only part we needed to update was a new hbs-template.
break out the decorators to avoid getting any node dependencies into cloudflare
Can you give more details here?
In general, I think the best approach would be to run the cli in node (using a custom template) and generate routes (which only require @tsoa/runtime
).
This is something you should be able to run in CF workers from there.
I just imported tsoa and got some issues with dependencies on node-buffers, but I should of course have used @tsoa/runtime instead. Tried it out now and it works just fine :) In that case the only update needed is custom template. Really neat!
Did a new version of this based on https://hono.dev which is my new favourite router as it works everywhere. Still early days but running it in production in a few projects now: https://www.npmjs.com/package/tsoa-hono