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

feat: add cors utils #322

Merged
merged 18 commits into from
Feb 16, 2023
Merged

feat: add cors utils #322

merged 18 commits into from
Feb 16, 2023

Conversation

NozomuIkuta
Copy link
Member

@NozomuIkuta NozomuIkuta commented Feb 8, 2023

Resolves #82
Related: NozomuIkuta/h3-cors#10

This PR is created according to @pi0's comment to my package.

I have upgraded h3 version in my package (and improved code coverage to 100% 👍).

Now, please review this PR and check whether I'm doing as you intended.

@NozomuIkuta NozomuIkuta requested a review from pi0 February 8, 2023 09:12
@NozomuIkuta NozomuIkuta self-assigned this Feb 8, 2023
src/utils/cors.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@pi0
Copy link
Member

pi0 commented Feb 8, 2023

Thanks for PR dear @NozomuIkuta.

Can we please directly inline the logic in h3 package? This way we can directly test and release it.

README.md Outdated
@@ -157,6 +157,7 @@ H3 has a concept of composable utilities that accept `event` (from `eventHandler
- `getSession(event, { password, name?, cookie?, seal?, crypto? })`
- `updateSession(event, { password, name?, cookie?, seal?, crypto? }), update)`
- `clearSession(event, { password, name?, cookie?, seal?, crypto? }))`
- `handleCors(options)` (see [h3-cors](https://github.com/NozomuIkuta/h3-cors) for more detail)
Copy link
Member Author

Choose a reason for hiding this comment

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

Let me consider it in another time how we can organize README, because it needs lots of words to explain CORS features. Or, we might want to create a Docus website for h3.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed. If possible adding help in JSDocs would be the best. In the future we should generate README baased on JSDocs and add more. Link is good for me until then 👍🏼

@codecov
Copy link

codecov bot commented Feb 8, 2023

Codecov Report

Merging #322 (636eca9) into main (e5bfd2f) will increase coverage by 2.39%.
The diff coverage is 96.05%.

❗ Current head 636eca9 differs from pull request most recent head 6a6138d. Consider uploading reports for the commit 6a6138d to get more accurate results

@@            Coverage Diff             @@
##             main     #322      +/-   ##
==========================================
+ Coverage   71.92%   74.32%   +2.39%     
==========================================
  Files          23       26       +3     
  Lines        2066     2294     +228     
  Branches      303      354      +51     
==========================================
+ Hits         1486     1705     +219     
- Misses        580      589       +9     
Impacted Files Coverage Δ
src/utils/cors/handler.ts 55.00% <55.00%> (ø)
src/utils/cors/index.ts 100.00% <100.00%> (ø)
src/utils/cors/utils.ts 100.00% <100.00%> (ø)
src/utils/index.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

src/utils/cors/handler.ts Outdated Show resolved Hide resolved
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

All nice work 💯 adding prefixes i think we can land it!

return defu(options, defaultOptions);
}

export function isPreflight(event: H3Event): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe isPreflightRequest?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed: 4636416

src/utils/cors/utils.ts Show resolved Hide resolved
}
| EmptyHeader;

export type AccessControlMaxAgeHeader =
Copy link
Member

Choose a reason for hiding this comment

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

Since we are exposing this types to end user, prefix would be better. (Do we really need to expose all individuals?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed: 052c215

I modified exports and make only CorsOptions public, which is useful to restrict argument type for CORS utilities (e.g. handleCors(event, corsOptions)).

@pi0 pi0 changed the title feat: add CORS support feat: add cors support Feb 8, 2023
@pi0 pi0 changed the title feat: add cors support feat: add cors utils Feb 8, 2023
@NozomuIkuta
Copy link
Member Author

It's worth merging content of NozomuIkuta/h3-cors#8 into this PR.
I will apply it as well as your feedback. 🙋‍♂️

@NozomuIkuta
Copy link
Member Author

#322 (comment) is fixed: bb7af39.

@NozomuIkuta
Copy link
Member Author

@pi0

I applied your feedback and the remaining PR (NozomuIkuta/h3-cors#8).
Let me request your review again. 🙋‍♂️

@NozomuIkuta NozomuIkuta requested a review from pi0 February 8, 2023 16:45
preflight: { statusCode },
} = resolveCorsOptions(options);

return defineEventHandler((event) => {
Copy link
Member

Choose a reason for hiding this comment

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

handle shouldn't create a wrapper handler but directly accept event to append required headers.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed: c1eef73

@NozomuIkuta NozomuIkuta requested a review from pi0 February 9, 2023 01:57
@NozomuIkuta
Copy link
Member Author

I added prefix "H3" to type names: 6f4bdc0

@pi0

Is there any more things that I should do for this PR?

@pi0
Copy link
Member

pi0 commented Feb 16, 2023

I have pushed couple of refactors. Really nice stuff thanks for helping to bring it to the core 👍🏼

@pi0 pi0 merged commit 080bf53 into main Feb 16, 2023
@pi0 pi0 deleted the feat/cors-support branch February 16, 2023 14:45
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.

CORS support
2 participants