如何通过 ngrok 访问子域? [英] How can I access a subdomain through ngrok?
本文介绍了如何通过 ngrok 访问子域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有api"子域的 rails 站点.我本地机器上的路由如下所示:
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
如何映射这两个子域?这是我的 ngrok 配置文件,但 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
推荐答案
如果您在路由中使用约束,我建议您使用如下约束类:
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
然后在你的 routes.rb
namespace :api do
constraints APIConstraint.new do
resources :some_resource
end
end
这篇关于如何通过 ngrok 访问子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文