Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting ROOT_URL with a path causes FlowRouter.url() to report incorrect url #684

Open
carlevans719 opened this issue Aug 25, 2016 · 5 comments · May be fixed by #691
Open

Setting ROOT_URL with a path causes FlowRouter.url() to report incorrect url #684

carlevans719 opened this issue Aug 25, 2016 · 5 comments · May be fixed by #691

Comments

@carlevans719
Copy link

If the ROOT_URL environment variable is set to contain a path (e.g. http://localhost:3000/app), FlowRouter.url() inserts an extra forward slash in the return value.

Repro: https://github.com/carlevans719/flow-router-root-url-repro

@carlevans719
Copy link
Author

Possibly related to 89fc983

@carlevans719
Copy link
Author

pathWithoutBase = pathWithoutBase.replace(/^\//, ''); on line 8 of lib/router.js resolves the issue

@Serubin
Copy link

Serubin commented Jan 19, 2017

I'm having a similar issue - I went through and added some logging to the FlowRouter.url() function and found this output:

  var completePath = this.path.apply(this, arguments);
  // /wekan/b
  var basePath = this._basePath || '/';
  // /wekan
  var pathWithoutBase = completePath.replace(new RegExp('^' + basePath), '');
  // /b
  return Meteor.absoluteUrl(pathWithoutBase);
  // https://mydomain.net/wekan//b

The router should definitely be taking out the leading slash.

Changing line 7 of lib/router.js to

var pathWithoutBase = completePath.replace(new RegExp('^(\/)|' + basePath), '');

An argument could be added for keeping that leading slash if necessary (ie. using a hashbang).

@sunhaolin
Copy link

sunhaolin commented Mar 15, 2017

@Serubin

var completePath = '/wekan/b';
var basePath = '/wekan';
var pathWithoutBase = completePath.replace(new RegExp('^(\/)|' + basePath), '');
Meteor.absoluteUrl(pathWithoutBase);
// "http://192.168.0.21/wekan/wekan/b"

@Serubin
Copy link

Serubin commented Mar 15, 2017

@sunhaolin Ah, yes. Good catch, thank you.

This should fix it and account for the slash immediately following the base path if it exists.

var pathWithoutBase = completePath.replace(new RegExp('^' + basePath + '(\/)'), '');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants