vercel.json is a static file. I need to allow a static website to allow multiple origins, for example example.com and subdomain.example.com.
With a dynamic server, we can dynamically generate a single origin value for Access-Control-Allow-Origin.
But how do we do this for a static website with vercel.json?
I read the docs here:
and here:
but neither of them specify how to allow a list of origins. I would assume that Vercel would run logic that sends the correct Access-Control-Allow-Origin header based on which origin is visiting a page.
But more specifically, if you need dynamic values for the allowed origins, you can use the Edge Middleware from Vercel, which is basically adding a middleware.ts file to the root of your project. There’s an example for that in the post I shared about.
Hi @trusktr, I understand your concern. I think you can use the has field of the header-object-definition to add multiple variations of response headers as follows: