Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cors helper #197

Merged
merged 15 commits into from
Dec 13, 2024
Merged

add cors helper #197

merged 15 commits into from
Dec 13, 2024

Conversation

ianmacartney
Copy link
Collaborator

a sketch of what it could look like w.r.t. composition vs. subclassing


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ianmacartney ianmacartney requested a review from tomredman August 5, 2024 20:30
@ianmacartney
Copy link
Collaborator Author

const http = httpRouter();

const httpWithCORS = corsRouter(http, {
  allowedOrigins: ["*"], // allow regex
  allowCredentials: false, // if true, must specify non-* origins
  allowMethods: ["*"],
  allowHeaders: ["*"],
  exposeHeaders: [],
  maxBrowserCacheAge: 600,
});

// route with the one based on what you want.
httpWithCORS.route({
  allowMethods: // overrides
  // normal fields
  path: "/myfn",
  action: "POST",
  handler: myhandler,
});

@ianmacartney ianmacartney force-pushed the ian/cors-helper branch 2 times, most recently from 5a5b225 to b7a08b1 Compare December 13, 2024 04:51
@ianmacartney ianmacartney changed the base branch from cors-helper to main December 13, 2024 04:51
@ianmacartney ianmacartney changed the title explore composition add cors helper Dec 13, 2024
@ianmacartney ianmacartney marked this pull request as ready for review December 13, 2024 04:52
@ianmacartney ianmacartney requested review from sshader and removed request for tomredman December 13, 2024 04:59
/**
* Non-CORS routes
*/
http.route({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do things like route to /foo with method GET with CORS and /foo with method POST without CORS? From a quick scan, looks like yes. I guess the OPTIONS will only reflect the ones with the CORS router, which is fine, but also probably not a super common case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually that's a bit of a rough edge: I believe if you route w/o CORS, then with CORS, the CORS router will include the non-cors method in the accepted methods

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll file an issue to track it

@ianmacartney ianmacartney merged commit 0675698 into main Dec 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants