4

「api」サブドメインを持つ Rails サイトを持っています。ローカル マシンのルートは次のようになります。

http://mysite.dev         #<-- normal web stuff
http://api.mysite.dev     #<-- my api

これら 2 つのサブドメインをマッピングするにはどうすればよいですか? これは私の ngrok 構成ファイルですが、API エンドポイントはベース ドメインを指しているようです。

tunnels:
web:
    subdomain: "my-project"
    proto:
        http: mysite.dev:5000
api:
    subdomain: "api.my-project"
    proto:
        http: api.mysite.dev:5000  
4

1 に答える 1

3

ルートで制約を使用している場合は、次のような制約クラスをお勧めします。

class APIConstraint

  def matches?(request)
     # I would extract the hard coded domains out into some config
     # file, but you get the idea..
     request.host == "ngrok.com" ? request.subdomain.include?("api") : request.subdomain == "api"
  end

end

そして、あなたのroutes.rb

namespace :api do
  constraints APIConstraint.new do
    resources :some_resource
  end
end
于 2015-02-20T20:52:32.117 に答える