deepkit-framework icon indicating copy to clipboard operation
deepkit-framework copied to clipboard

feat(cloudflare): cloudflare workers support for http & rpc packages

Open marcus-sa opened this issue 3 years ago • 6 comments

Summary of changes

Initial implementation of Cloudflare Workers support for HTTP & RPC.

TODO

  • [ ] Auth

Blockers

Relinquishment of Rights

Please mark following checkbox to confirm that you relinquish all rights of your changes:

  • [x] I waive and relinquish all rights regarding this changes (including code, text, and images) to Deepkit UG (limited), Germany. This changes (including code, text, and images) are under MIT license without name attribution, copyright notice, and permission notice requirement.

marcus-sa avatar May 24 '22 12:05 marcus-sa

Note: we found out Cloudfare doesn't support new Function and thus does not support Deepkit.

marcj avatar Jul 12 '22 12:07 marcj

maybe providing an option to opt-out of jit?

hanayashiki avatar Jul 21 '22 11:07 hanayashiki

maybe providing an option to opt-out of jit?

Too much effort for too little reward. It'd be better to ask Cloudflare to provide an option that'll enable support for new Function.

marcus-sa avatar Jul 21 '22 12:07 marcus-sa

Unlikely. Edge runtime takes security so seriously that they ban dynamic codes 😅

hanayashiki avatar Jul 21 '22 13:07 hanayashiki

I definitely do not rewrite the core of Deepkit's libraries just to support one platforms's "security" decision (which is no security related decision).

marcj avatar Jul 21 '22 14:07 marcj

Not an expert on cloudflare, but as a workaround it should be easy to write a new file (with the validation function) and import that dynamically. it's basically the same as using new Function();

ps: also this way an AOT could be implemented

CristianPi avatar Aug 01 '22 15:08 CristianPi

@CristianPi it could be interesting. I think if we can get DI running the rest would be easy.

Rush avatar Oct 09 '22 03:10 Rush

Note: we found out Cloudfare doesn't support new Function and thus does not support Deepkit.

From what I search the codebase using: https://github.com/search?q=%22new+Function%28%22+repo%3Adeepkit%2Fdeepkit-framework&type=Code&ref=advsearch&l=&l=

Only bson seems to be an issue when running inside Cloudflare, the compiler package I assume is only used during compilation.

@marcj did I miss something?

H4ad avatar Oct 09 '22 05:10 H4ad

From what I understand JIT (new Function) is instrumental to almost everything :)

Rush avatar Oct 09 '22 05:10 Rush

This is because "compilation" actually happens at runtime.

Rush avatar Oct 09 '22 05:10 Rush

From what I understand JIT (new Function) is instrumental to almost everything :)

Yeah, Deepkit creates dynamically optimized JIT functions under the hood.

marcus-sa avatar Oct 11 '22 22:10 marcus-sa

very interested in this if it were to work.

4x4notfound avatar Dec 19 '22 13:12 4x4notfound

Not an expert on cloudflare, but as a workaround it should be easy to write a new file (with the validation function) and import that dynamically. it's basically the same as using new Function();

ps: also this way an AOT could be implemented

Does cf worker ever provides a file system?

hanayashiki avatar Dec 27 '22 07:12 hanayashiki

No

marcus-sa avatar Dec 27 '22 18:12 marcus-sa