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

[CORE] Feat/issue 193 - Enable cors #201

Closed

Conversation

iam-oov
Copy link
Contributor

@iam-oov iam-oov commented May 2, 2022

Enable CORS.
Resolve issue 193.

@iam-oov iam-oov added the feature This is a feature label May 16, 2022
@@ -18,6 +19,11 @@ const fastify = Fastify({
logger: !isTestEnv,
});

// Enable cors
fastify.register(require('@fastify/cors'), {
origin: configCORS.domain,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to add these options

  • credentials: this enables to share cookies in requests, I suggest to talk with other teams and know if that's the case this should set to true. Here more information
  • methods: fastify-cors doesn't say how will behave if this parameter is omitted, so I think we should add it
    allowHeaders: the default behavior is

reflecting the headers specified in the request's Access-Control-Request-Headers header.
Here you can find more information about it.
Is that what you want?

  • optionSuccessStatus: to avoid to having conflict with default 204 code with legacy browsers
  • exposedHeaders: this just if we create custom headers. Do you talk with the rest of cohort if someone is going to need that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the comments. i will read all the documentation to make a configuration closer to production.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was searching about optionSuccesStatus, I think you can omit that value since almost all browsers accept 204 value (default value). Here you can see 204 code compatibility with browsers

Copy link
Contributor Author

@iam-oov iam-oov May 19, 2022

Choose a reason for hiding this comment

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

For the moment I only set the credentials to true to activate the cookies.
But the other keys I think it is better that they stay like this so as not to put more barriers and interrupt the progress of the other squads.

I don't think it's feasible to change the key "domain" to list because our requirement is to use only one domain and not several.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, the documentation doesn't say about default behavior in that field, so I would recommend to add all the methods (to make a fast solution)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ready!

const prefix = require('./environment');

module.exports = {
domain: process.env[`${prefix}CORS_DOMAIN`],
Copy link
Contributor

@essau-net essau-net May 17, 2022

Choose a reason for hiding this comment

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

Do you talk with our cohort about third services needed? If we need more that one, this value should be an array. In order to accomplish that we need to separate values with commas and use split function.
Here more information about creating an array using env vars

@iam-oov iam-oov closed this May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CORE] feat: Enable CORS
2 participants