Skip to content

Commit

Permalink
Merge pull request #293 from tightenco/jbk/cross-domain-port
Browse files Browse the repository at this point in the history
Fix missing port value across subdomains
  • Loading branch information
bakerkretzmar authored Jun 5, 2020
2 parents 1eccdf2 + 3d3a759 commit 13e4740
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
10 changes: 7 additions & 3 deletions dist/js/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,11 @@ function () {
if (!this.absolute) return '/';
if (!this.route.domain) return this.ziggy.baseUrl.replace(/\/?$/, '/');
var host = (this.route.domain || this.ziggy.baseDomain).replace(/\/+$/, '');
if (this.ziggy.basePort && host.replace(/\/+$/, '') === this.ziggy.baseDomain.replace(/\/+$/, '')) host = this.ziggy.baseDomain + ':' + this.ziggy.basePort;

if (this.ziggy.basePort) {
host = "".concat(host, ":").concat(this.ziggy.basePort);
}

return this.ziggy.baseProtocol + '://' + host + '/';
}
}, {
Expand Down Expand Up @@ -1100,11 +1104,11 @@ function (_String) {
} else {
tagValue = _this2.urlParams[keyName];
delete _this2.urlParams[keyName];
} // The type of the value is undefined; is this param
} // The value is null or defined; is this param
// optional or not


if (typeof tagValue === 'undefined') {
if (tagValue == null) {
if (tag.indexOf('?') === -1) {
throw new Error("Ziggy Error: '" + keyName + "' key is required for route '" + _this2.name + "'");
} else {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/route.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/js/UrlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class UrlBuilder {

let host = (this.route.domain || this.ziggy.baseDomain).replace(/\/+$/, '');

if (this.ziggy.basePort && (host.replace(/\/+$/, '') === this.ziggy.baseDomain.replace(/\/+$/, '')))
host = this.ziggy.baseDomain + ':' + this.ziggy.basePort;
if (this.ziggy.basePort) {
host = `${host}:${this.ziggy.basePort}`;
}

return this.ziggy.baseProtocol + '://' + host + '/';
}
Expand Down
6 changes: 3 additions & 3 deletions tests/js/test.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ describe('route()', function() {
global.Ziggy.basePort = orgBasePort;
});

it('Should return correct URL without port when run with params on a route with required domain params', function() {
it('Should return correct URL with port when run with params on a route with required domain params', function() {
let orgBaseUrl = Ziggy.baseUrl;
let orgBaseDomain = Ziggy.baseDomain;
let orgBasePort = Ziggy.basePort;
Expand All @@ -501,11 +501,11 @@ describe('route()', function() {
global.Ziggy.basePort = 81;

assert.equal(
'http://tighten.myapp.dev/users/1',
'http://tighten.myapp.dev:81/users/1',
route('team.user.show', { team: 'tighten', id: 1 })
);
assert.equal(
'http://tighten.myapp.dev/users/1',
'http://tighten.myapp.dev:81/users/1',
route('team.user.show').with({ team: 'tighten', id: 1 })
);

Expand Down

0 comments on commit 13e4740

Please sign in to comment.