tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Support Cloudflare Workers

Open markusahlstrand opened this issue 2 years ago • 6 comments

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

markusahlstrand avatar Dec 18 '22 10:12 markusahlstrand

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.👀

github-actions[bot] avatar Dec 18 '22 10:12 github-actions[bot]

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.

WoH avatar Jan 05 '23 19:01 WoH

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.

markusahlstrand avatar Jan 05 '23 21:01 markusahlstrand

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.

WoH avatar Jan 05 '23 22:01 WoH

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!

markusahlstrand avatar Jan 06 '23 17:01 markusahlstrand

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

markusahlstrand avatar Sep 28 '23 15:09 markusahlstrand