我有一个带有" api"子域。我本地计算机上的路由如下所示:
http://mysite.dev #<-- normal web stuff
http://api.mysite.dev #<-- my api
如何映射这两个子域?这是我的ngrok配置文件,但api端点似乎指向基本域。
tunnels:
web:
subdomain: "my-project"
proto:
http: mysite.dev:5000
api:
subdomain: "api.my-project"
proto:
http: api.mysite.dev:5000
答案 0 :(得分: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