-1

My URL list look like this

const urls = ["example1.com", "exam.com"]

My cors setting look like this:

  const cors = require("fastify-cors")

  // Enable CORS
  fastify.register(cors, {
    origin: '*',
    methods: ['GET', 'POST'],
    credentials: true
  })

2 Answers2

0

From the Fasify-Cors docs you can use array in origin option. Read for more

Your example could be:

const cors = require("@fastify/cors")

  // Enable CORS
  fastify.register(cors, {
    origin: ["example1.com", "exam.com"],
    methods: ['GET', 'POST'],
    credentials: true
  })
0

fastify-cors has been deprecated. Please use @fastify/cors instead.

For your version, this is the documentation.

const cors = require("fastify-cors")
const urls = ["example1.com", "exam.com"]

// Enable CORS
fastify.register(cors, {
  origin: urls,
  methods: ['GET', 'POST'],
  credentials: true
})
Ridham Tarpara
  • 5,970
  • 4
  • 19
  • 39