Skip to content

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

@gilles-crealp

Description

@gilles-crealp

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions