Skip to content

Conversation

@baoshan
Copy link
Contributor

@baoshan baoshan commented Jul 14, 2021

Follow up to octokit/auth-oauth-user-client.js#1 (comment)

This commit distills the original Node.js/Express middleware into a runtime agnostic HTTP handler which operates on a generalized request/response interface rather than IncomingMessage.

This handler hopefully can better support different runtimes (Cloudflare/Deno/AWS Lambda) with the same behavior, so the client authentication strategy can also be backend-or-platform-agnostic.

The new Node.js/Express middleware relies on the generalized HTTP handler. Test file is untouched to respect the current behavior.

fromentries dependency is removed since Node.js v10 is out of maintanence.

@wolfy1339
Copy link
Member

wolfy1339 commented Jul 14, 2021

fromentries dependency is removed since Node.js v10 is out of maintanence.

We still support NodeJS v10 for now, until our next major version bump

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay this is quite a lot 😁 I like your approach, but I think you've done two steps at once. I think it would have been a better approach to first create a Cloudflare Worker middleware and get it merged. And once we have that we could have looked into abstractions. But with only two use cases I fear that an abstraction might be premature and cause more work down the path, I'd probably looked into yet another middleware that is as different as possible to Node's and Cloudflare's.

But that's okay now, I'm just thinking out loud, let's be pragmatic about it. For now, can you please address my comments?

Could you also please add README.md files with some explanations in src/middleware (what is this folder / how to build your own middleware) and src/midleware/node (how to use the node/express middleware)

@baoshan baoshan force-pushed the runtime-agnostic-middleware branch 7 times, most recently from ec73b49 to 1755cd2 Compare July 15, 2021 15:10
@gr2m gr2m force-pushed the runtime-agnostic-middleware branch from 1755cd2 to 3852189 Compare July 15, 2021 18:02
@gr2m
Copy link
Contributor

gr2m commented Jul 15, 2021

I resolved the conflict and workedaround a typescript error. I had to force-push the changes so watch out if you continue working on it. This also triggered the full CI on the PR

3. Expose an HTTP handler/middleware in the dialect of the environment which performs three steps:
1. Parse the HTTP request using (1).
2. Process the `OctokitRequest` object using `handleRequest`. If the request is not handled by `handleRequest` (the request does not match any predefined route), [`onUnhandledRequestDefault`](on-unhandled-request-default.ts) can be used to generate a `404` response consistently.
3. Render the `OctokitResponse` object using (2).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the README, this is great!

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot, I really like how readable the node middleware code is now!

To share the bigger picture of middlewares in Octokit land: we do have the concept several @octokit/* modules, some of which depend on each other.

I think once we are happy with the implementation in @octokit/oauth-app, it would make sense to look to move the abstract middleware to handler requests/responses into its own module, so that the other packages can utilize it. No need to worry about it now, just wanted to mention it so you better understand the context of where I'm coming from

@@ -1,59 +1,21 @@
// remove type imports from http for Deno compatibility
// see https://github.com/octokit/octokit.js/issues/24#issuecomment-817361886
// see https://github.com/octokit/octokit.js/issues/2075#issuecomment-817361886
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, thank you for fixing it!

@gr2m gr2m merged commit d3a7b38 into octokit:master Jul 15, 2021
@baoshan baoshan deleted the runtime-agnostic-middleware branch July 16, 2021 00:57
@github-actions
Copy link

🎉 This PR is included in version 3.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Copy link

@Lekir1 Lekir1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed spam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants