【问题标题】:Meteor's FlowRouter.url() returning IP address of host, not FQDNMeteor 的 FlowRouter.url() 返回主机的 IP 地址,而不是 FQDN
【发布时间】:2017-01-18 17:28:46
【问题描述】:

调用时:

FlowRouter.url("myRouteName");

我正在获取服务器的 IP 地址,即

"http://XX.XXX.XX.XXX/loggedin/my-route"

而不是 FQDN,即

"http://example.com/loggedin/my-route"

知道如何正确配置吗?

谢谢。


【问题讨论】:

  • 你的ROOT_URL环境变量设置了吗?
  • 好问题。这可以处理多个站点吗?通过 example.xyz、example.co.uk、example.in 等访问实例。
  • ROOT_URL 只能指定一个 URL,但您可以执行以下两种操作之一:(1) 指定单个 URL,例如 example.xyz,您的实例将始终使用该 URL Meteor.absoluteUrl,无论该 URL 用于访问该站点。 (2) 每个可能的 URL 有一个实例,每个实例具有正确的 ROOT_URL。 (2) 可能是您想要的,但这取决于您正在使用多少个可能的域,以及数量是否是动态的。

标签: meteor flow-router


【解决方案1】:

回答我自己的问题。 Source.

Router.prototype.url = function() {
  // We need to remove the leading base path, or "/", as it will be inserted
  // automatically by `Meteor.absoluteUrl` as documented in:
  // http://docs.meteor.com/#/full/meteor_absoluteurl
  var completePath = this.path.apply(this, arguments);
  var basePath = this._basePath || '/';
  var pathWithoutBase = completePath.replace(new RegExp('^' + basePath), '');
  return Meteor.absoluteUrl(pathWithoutBase);
};

看来 FlowRouter 正在使用Meteor.absoluteUrl

现在可以使用Meteor.absoluteUrl.defaultOptions.rootUrl = "http://example.com" 设置绝对路径,但这对我来说不是正确的方法,因为我的应用实际上可以提供多个域名。

所以我必须编写自己的函数,从客户端提取 FQDN,即席。

flowRouterUrl = function(id, params, queryParams) {
    return window.location.protocol + "//" + window.location.host + FlowRouter.path(id, params, queryParams);
}

flowRouterUrl("myRoute");

返回

http://example.com/loggedin/my-route

这是我所追求的。

【讨论】:

    猜你喜欢
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多