mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Add the replaceLocalhost option to Meteor.absoluteUrl
This commit is contained in:
@@ -25,7 +25,7 @@ Template.api.startup = {
|
||||
};
|
||||
|
||||
Template.api.absoluteUrl = {
|
||||
id: "meteor_absoluteUrl",
|
||||
id: "meteor_absoluteurl",
|
||||
name: "Meteor.absoluteUrl([path], [options])",
|
||||
locus: "Anywhere",
|
||||
descr: ["Generate an absolute URL pointing to the application. The server "
|
||||
@@ -44,6 +44,9 @@ Template.api.absoluteUrl = {
|
||||
type: "Boolean",
|
||||
descr: "Create an HTTPS URL."
|
||||
},
|
||||
{name: "replaceLocalhost",
|
||||
type: "Boolean",
|
||||
descr: "Replace localhost with 127.0.0.1. Useful for services that don't recognize localhost as a domain name."},
|
||||
{name: "rootUrl",
|
||||
type: "String",
|
||||
descr: "Override the default ROOT_URL from the server environment. For example: \"`http://foo.example.com`\""
|
||||
|
||||
@@ -16,7 +16,6 @@ and removed with:
|
||||
|
||||
$ meteor remove <package_name>
|
||||
|
||||
{{> pkg_absolute_url}}
|
||||
{{> pkg_amplify}}
|
||||
{{> pkg_backbone}}
|
||||
{{> pkg_bootstrap}}
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
!/http:\/\/127\.0\.0\.1[:\/]/.test(url)) // or 127.0.0.1
|
||||
url = url.replace(/^http:/, 'https:');
|
||||
|
||||
if (options.replaceLocalhost)
|
||||
url = url.replace(/^http:\/\/localhost([:\/].*)/, 'http://127.0.0.1$1');
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,6 +36,27 @@ Tinytest.add("absolute-url - basics", function(test) {
|
||||
test.equal(Meteor.absoluteUrl('foo', {rootUrl: 'http://127.0.0.1:3000',
|
||||
secure: true}),
|
||||
'http://127.0.0.1:3000/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');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user