我正在使用带有 Rail 5.1 API 的rack-cors gem。
根据文档,我有以下初始化程序:
配置/初始化器/cors.rb
module Api
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins ['http://localhost:4200','https://app.mydomain.com/']
resource '*',
headers: :any,
:expose => ['access-token', 'expiry', 'token-type', 'uid', 'client'],
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
end
然而,这意味着当部署到生产环境时,我的 api 将接受来自任何localhost:4200
origin.
如何将这些设置分开,以便不同的环境可以具有不同的允许来源?