blomqma / next-rest-framework

Type-safe, self-documenting APIs for Next.js
https://next-rest-framework.vercel.app
Other
136 stars 18 forks source link

Make Edge compatible #115

Closed SaadBazaz closed 7 months ago

SaadBazaz commented 8 months ago

Hey, As always. Superfan.

I want to use NRF as a standard for literally everything I build, but, recently I wanted to use it in an Edge function. Unfortunately, the Vercel Edge comes with some limitations; a lot of underlying Node utilities are not available.

Here's what NRF tries to access, which the Edge does not provide:

Screenshot 2023-12-21 at 16 27 38

Can we either: 1) Use Edge-compatible alternatives, or, 2) Have a graceful fallback incase these utilities are not present, or, 3) Have a lighter version of the lib?

blomqma commented 8 months ago

That should be doable as the Node.js file system APIs etc. that are not available in edge runtime, should only be needed in development mode and when generating the OpenAPI spec file. Need to come up with some way to split the code in order to achieve this.

cmaycumber commented 8 months ago

I'm in the same boat as @SaadBazaz. If there's anything I can do to help I'd love to see edge functions in next-rest-framework. It seems like this would be great for our external and internal API's.

blomqma commented 8 months ago

I'm in the same boat as @SaadBazaz. If there's anything I can do to help I'd love to see edge functions in next-rest-framework. It seems like this would be great for our external and internal API's.

Well, solving this is not trivial so this is not a typical "good first issue" but all contributions are welcome of course. I believe this requires at least a new way to split the code using a module bundler as well as possibly replacing some of the dependencies with edge-compatible correspondants and I can't promise solving this within a week or two so this will take some time to further investigate from my side.

SaadBazaz commented 8 months ago

I'm in the same boat as @SaadBazaz. If there's anything I can do to help I'd love to see edge functions in next-rest-framework. It seems like this would be great for our external and internal API's.

Well, solving this is not trivial so this is not a typical "good first issue" but all contributions are welcome of course. I believe this requires at least a new way to split the code using a module bundler as well as possibly replacing some of the dependencies with edge-compatible correspondants and I can't promise solving this within a week or two so this will take some time to further investigate from my side.

Agreed. The code-splitting part can potentially become a maintenance nightmare. We may have to look into dependency injection patterns for this 👀

blomqma commented 7 months ago

Giving an update that I'm currently working on this with promising results so far. Hoping to get https://github.com/blomqma/next-rest-framework/pull/119 merged and released within a week or so, there's plenty of things to test and document for the Edge runtime support.

blomqma commented 7 months ago

I have now released v5.0.0 which adds support for Edge runtime, please check the release notes before upgrading: https://github.com/blomqma/next-rest-framework/releases/tag/v5.0.0