如何通过ngrok访问子域?
我有一个带有“api”子域的rails站点。 我本地计算机上的路由如下所示:
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
如果你在你的路线中使用约束,我会建议一个约束类,如下所示:
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