How can I access a subdomain through ngrok?

梦想的初衷 提交于 2019-12-30 10:57:43

问题


I have a rails site with an "api" subdomain. The routes on my local machine look like this:

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

How can I map these two subdomains? This is my ngrok config file, but the api endpoint seems to point to the base domain.

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

回答1:


In case you are using Constraints in your routes, I would suggest a constraint class such as the following:

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

And then in your routes.rb

namespace :api do
  constraints APIConstraint.new do
    resources :some_resource
  end
end


来源:https://stackoverflow.com/questions/28637457/how-can-i-access-a-subdomain-through-ngrok

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!