Conditionally providing origins based on environment for Corsica

Hello all I was encountering CORS issues with getting my Phoenix API on Fly to accept comms from my NextJS client on Vercel. I finally got it working, but I am not happy about putting this out into production because of that http://localhost:3000. I would like to provide that as the origin when running in :dev and then when running in :prod run the regex origin to match Vercel urls. I am not sure how to go about doing this and also it would need to work on Fly too.

plug(Corsica,
    # ...
    origins: [~r{vercel-deployment-preview-urls}, "http://localhost:3000"]
  )
1 Like

What about a basic case ?
Something along the lines of

case Env do
     :dev -> "http//localhost:3000"
     _ -> ~r{vercel}
end

Wherever you use your atom must a elixir file, so conditionnal constructs should be available.

1 Like

You can use MFA tuple or decide during compilation time as @AUGERClement have shown.

1 Like