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

Make all routes relative to ROOT_URL to support reverse proxies #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ Url.parse = function (url) {

var match = url.match(re);

var pathPrefix = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
var protocol = match[1] ? match[1].toLowerCase() : undefined;
var hostWithSlashes = match[3];
var slashes = !!hostWithSlashes;
Expand All @@ -181,8 +182,8 @@ Url.parse = function (url) {
var hostWithPortParts = (host && host.split(':')) || [];
var hostname = hostWithPortParts[0];
var port = hostWithPortParts[1];
var origin = (protocol && host) ? protocol + '//' + host : undefined;
var pathname = match[5];
var origin = (protocol && host) ? protocol + '//' + host + pathPrefix : undefined;
var pathname = match[5].replace(pathPrefix, '');
var hash = match[8];
var originalUrl = url;

Expand All @@ -205,16 +206,13 @@ Url.parse = function (url) {
var path = pathname + (search || '');
var queryObject = Url.fromQueryString(query);

var rootUrl = [
protocol || '',
slashes ? '//' : '',
hostWithAuth || ''
].join('');
var rootUrl = __meteor_runtime_config__.ROOT_URL;

var href = [
protocol || '',
slashes ? '//' : '',
hostWithAuth || '',
pathPrefix || '',
pathname || '',
search || '',
hash || ''
Expand Down Expand Up @@ -366,6 +364,8 @@ Url.prototype.resolve = function (params, options) {
}
}

path = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + path;

// Because of optional possibly empty segments we normalize path here
path = path.replace(/\/+/g, '/'); // Multiple / -> one /
path = path.replace(/^(.+)\/$/g, '$1'); // Removal of trailing /
Expand Down