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

Allow the special * value in array in origin option #243

Closed
2 tasks done
gilles-crealp opened this issue Mar 13, 2023 · 3 comments · Fixed by #244
Closed
2 tasks done

Allow the special * value in array in origin option #243

gilles-crealp opened this issue Mar 13, 2023 · 3 comments · Fixed by #244

Comments

@gilles-crealp
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Recognise the special * value in array type origin option.

Motivation

When using this plugin with env-schema or fastify-env, I have to switch from string in dev (for *) to array in production (with separator: ',' for multiple origins).

Example

import fastify from 'fastify'
import fastifyCors from '@fastify/cors'
import envSchema from 'env-schema'

const config = envSchema({
  dotenv: true,
  schema: {
    type: 'object',
    properties: {
      CORS_ORIGIN: {
        type: 'string',
        separator: ',',
        default: '*'
      }
    }
  }
})

const server = fastify()

server.register(fastifyCors, {
  origin: config.CORS_ORIGIN
})

server.listen()
@mcollina
Copy link
Member

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@Uzlopak
Copy link
Contributor

Uzlopak commented Mar 13, 2023

provided a PR #244

@gilles-crealp
Copy link
Author

OK, @Uzlopak was more reactive than me. Thank you!

@Eomm Eomm closed this as completed in #244 Mar 14, 2023
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 a pull request may close this issue.

3 participants