mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Allow ROOT_URL to not contain http://
This commit is contained in:
@@ -11,6 +11,9 @@ Meteor.absoluteUrl = function (path, options) {
|
||||
if (!url)
|
||||
throw new Error("Must pass options.rootUrl or set ROOT_URL in the server environment");
|
||||
|
||||
if (!/^http[s]?:\/\//i.test(url)) // url starts with 'http://' or 'https://'
|
||||
url = 'http://' + url; // we will later fix to https if options.secure is set
|
||||
|
||||
if (!/\/$/.test(url)) // url ends with '/'
|
||||
url += '/';
|
||||
|
||||
|
||||
@@ -1,62 +1,65 @@
|
||||
Tinytest.add("absolute-url - basics", function(test) {
|
||||
|
||||
test.equal(Meteor.absoluteUrl({rootUrl: 'http://asdf.com'}),
|
||||
'http://asdf.com/');
|
||||
test.equal(Meteor.absoluteUrl(undefined, {rootUrl: 'http://asdf.com'}),
|
||||
'http://asdf.com/');
|
||||
test.equal(Meteor.absoluteUrl(undefined, {rootUrl: 'http://asdf.com/'}),
|
||||
'http://asdf.com/');
|
||||
_.each(['', 'http://'], function (prefix) {
|
||||
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://asdf.com/'}),
|
||||
'http://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('/foo', {rootUrl: 'http://asdf.com'}),
|
||||
'http://asdf.com//foo');
|
||||
test.equal(Meteor.absoluteUrl('#foo', {rootUrl: 'http://asdf.com'}),
|
||||
'http://asdf.com/#foo');
|
||||
test.equal(Meteor.absoluteUrl({rootUrl: prefix + 'asdf.com'}),
|
||||
'http://asdf.com/');
|
||||
test.equal(Meteor.absoluteUrl(undefined, {rootUrl: prefix + 'asdf.com'}),
|
||||
'http://asdf.com/');
|
||||
test.equal(Meteor.absoluteUrl(undefined, {rootUrl: prefix + 'asdf.com/'}),
|
||||
'http://asdf.com/');
|
||||
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://asdf.com',
|
||||
secure: true}),
|
||||
'https://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'https://asdf.com',
|
||||
secure: true}),
|
||||
'https://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'https://asdf.com',
|
||||
secure: false}),
|
||||
'https://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'asdf.com/'}),
|
||||
'http://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('/foo', {rootUrl: prefix + 'asdf.com'}),
|
||||
'http://asdf.com//foo');
|
||||
test.equal(Meteor.absoluteUrl('#foo', {rootUrl: prefix + 'asdf.com'}),
|
||||
'http://asdf.com/#foo');
|
||||
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://localhost',
|
||||
secure: true}),
|
||||
'http://localhost/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://localhost:3000',
|
||||
secure: true}),
|
||||
'http://localhost:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'https://localhost:3000',
|
||||
secure: true}),
|
||||
'https://localhost:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://127.0.0.1:3000',
|
||||
secure: true}),
|
||||
'http://127.0.0.1:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'asdf.com',
|
||||
secure: true}),
|
||||
'https://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'https://asdf.com',
|
||||
secure: true}),
|
||||
'https://asdf.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'https://asdf.com',
|
||||
secure: false}),
|
||||
'https://asdf.com/foo');
|
||||
|
||||
// test replaceLocalhost
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://localhost:3000',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://localhost',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://127.0.0.1:3000',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://127.0.0.1',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1/foo');
|
||||
// don't replace just any localhost
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://foo.com/localhost',
|
||||
replaceLocalhost: true}),
|
||||
'http://foo.com/localhost/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://foo.localhost.com',
|
||||
replaceLocalhost: true}),
|
||||
'http://foo.localhost.com/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'localhost',
|
||||
secure: true}),
|
||||
'http://localhost/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'localhost:3000',
|
||||
secure: true}),
|
||||
'http://localhost:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'https://localhost:3000',
|
||||
secure: true}),
|
||||
'https://localhost:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + '127.0.0.1:3000',
|
||||
secure: true}),
|
||||
'http://127.0.0.1:3000/foo');
|
||||
|
||||
// test replaceLocalhost
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'localhost:3000',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'localhost',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + '127.0.0.1:3000',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1:3000/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + '127.0.0.1',
|
||||
replaceLocalhost: true}),
|
||||
'http://127.0.0.1/foo');
|
||||
// don't replace just any localhost
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'foo.com/localhost',
|
||||
replaceLocalhost: true}),
|
||||
'http://foo.com/localhost/foo');
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: prefix + 'foo.localhost.com',
|
||||
replaceLocalhost: true}),
|
||||
'http://foo.localhost.com/foo');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user