Meteor's FlowRouter.url() returning IP address of host, not FQDN

651 Views Asked by At

When calling:

FlowRouter.url("myRouteName");

I'm getting the IP address of the server, i.e

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

Instead of the FQDN, i.e

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

Any idea how this can be configured properly?

Thanks.


1

There are 1 best solutions below

0
On

Answering my own question. 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);
};

So it seems FlowRouter is using Meteor.absoluteUrl.

Now the absolute path can be set with Meteor.absoluteUrl.defaultOptions.rootUrl = "http://example.com" However this isn't the correct approach for me, as my app can actually serve multiple domain names.

So I'll have to write my own function, which extracts the FQDN from the client, ad hoc.

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

flowRouterUrl("myRoute");

returns

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

Which is what I'm after.