-
Notifications
You must be signed in to change notification settings - Fork 17
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
add cors helper #197
Conversation
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,
}); |
e5b9e88
to
8850c73
Compare
5a5b225
to
b7a08b1
Compare
b7a08b1
to
23b0832
Compare
/** | ||
* Non-CORS routes | ||
*/ | ||
http.route({ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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.