LoginSignup
4
0

More than 3 years have passed since last update.

環境変数で配列もハッシュも扱いたい

Posted at

how

JSONにして、アプリケーション側でパースする
以上。

環境変数を入れる

bashで

$ CORS_DOMAINS_JSON='["sample.com", "example.com"]'

docker-compose.ymlで

docker-compose.yml
    environment:
      - CORS_DOMAINS_JSON=["sample.com", "example.com"]

環境変数をパースして使う

railsのrack-corsとか

config/application.json
    config.middleware.insert_before 0, Rack::Cors do
      allow do
        origins JSON.parse(ENV.fetch('CORS_DOMAINS_JSON') { '[]' })
        resource "*",
          credentials: true,
          headers: :any,
          methods: [:get, :post, :options, :head, :patch, :delete]
      end
    end

その他各使用環境に合わせてjsonをパースするだけ

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0