Skip to content

Commit

Permalink
Fix error about Npm not being defined on client side
Browse files Browse the repository at this point in the history
  • Loading branch information
jparyani committed Oct 7, 2014
1 parent 11c0d7d commit 54bfa9c
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions shell/shared/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,23 @@ makeWildcardHost = function (id) {
return wildcardHost[0] + id + wildcardHost[1];
}

var Url = Npm.require("url");
getWildcardOrigin = function () {
// The wildcard URL can be something like "foo-*-bar.example.com", but sometimes when we're
// trying to specify a pattern matching hostnames (say, a Content-Security-Policy directive),
// an astrisk is only allowed as the first character and must be followed by a period. So we need
// "*.example.com" instead -- which matches more than we actually want, but is the best we can
// really do. We also add the protocol to the front (again, that's what CSP wants).

// TODO(cleanup): `protocol` is computed in other files, like proxy.js. Put it somewhere common.
var protocol = Url.parse(process.env.ROOT_URL).protocol;

var dotPos = wildcardHost[1].indexOf(".");
if (dotPos < 0) {
return protocol + "//*";
} else {
return protocol + "//*" + wildcardHost[1].slice(dotPos);
if (Meteor.isServer) {
var Url = Npm.require("url");
getWildcardOrigin = function () {
// The wildcard URL can be something like "foo-*-bar.example.com", but sometimes when we're
// trying to specify a pattern matching hostnames (say, a Content-Security-Policy directive),
// an astrisk is only allowed as the first character and must be followed by a period. So we need
// "*.example.com" instead -- which matches more than we actually want, but is the best we can
// really do. We also add the protocol to the front (again, that's what CSP wants).

// TODO(cleanup): `protocol` is computed in other files, like proxy.js. Put it somewhere common.
var protocol = Url.parse(process.env.ROOT_URL).protocol;

var dotPos = wildcardHost[1].indexOf(".");
if (dotPos < 0) {
return protocol + "//*";
} else {
return protocol + "//*" + wildcardHost[1].slice(dotPos);
}
}
}

0 comments on commit 54bfa9c

Please sign in to comment.