Code Monkey home page Code Monkey logo

Comments (3)

thiamsantos avatar thiamsantos commented on July 20, 2024 4

@jfcalvo As far as I know that happens because the place where the config is fetched, the init/1 callback of the plug runs at compile-time. So when the release starts and update the config, the previous value is already inlined by the compiler.

What I usually do is to pass a function that returns the allowed origins, as described in the docs. And in there, I make sure to fetch the config at runtime.

# endpoint.ex
plug CORSPlug, origin: &MyCors.my_fun/0

# my_cors.ex
defmodule MyCors do
  def my_fun do
    Application.fetch_env!(:my_app, :my_allowed_origins)
  end
end

# config/releases.exs
config :my_app, my_allowed_origins: System.fetch_env!("MY_CORS_ORIGIN")

from cors_plug.

mjc avatar mjc commented on July 20, 2024 2

with elixir 1.9 releases you put the dynamic stuff in config/releases.exs like this:

import Config
config :cors_plug, origin: [System.fetch_env!("CORS_ORIGIN")]

https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-runtime-configuration

if you imported Mix.Config instead of Config it would reproduce the behavior you're seeing, I'm pretty sure.

from cors_plug.

mschae avatar mschae commented on July 20, 2024

I'm considering this closed for now, please let me know if there is anything I can do on my end and I'll reopen!

from cors_plug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.