Skip to content

Commit

Permalink
Add initial mechanics for serving an app on a path other than /
Browse files Browse the repository at this point in the history
For now, this requires the ABSOLUTE_URL environment to be set to true.  More
considered ABI possibly coming.
  • Loading branch information
Naomi Seyfer committed Jun 13, 2013
1 parent fc74cfb commit 213cd94
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
3 changes: 2 additions & 1 deletion packages/ctl/ctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Ctl.Commands.push({
Ctl.prettyCall(Ctl.findGalaxy(), 'run', [Ctl.myAppName(), 'server', {
exitPolicy: 'restart',
env: {
METEOR_DEPLOY_CONFIG: JSON.stringify(deployConfig)
METEOR_DEPLOY_CONFIG: JSON.stringify(deployConfig),
ROOT_URL: appConfig.sitename
},
ports: {
"main": {
Expand Down
3 changes: 3 additions & 0 deletions packages/livedata/stream_client_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ var translateUrl = function(url, newSchemeBase, subPath) {
url = newSchemeBase + "://" + url;
}

if (__meteor_runtime_config__.ABSOLUTE_URL && startsWith(url, "/"))
url = Meteor.absoluteUrl() + url;

if (endsWith(url, "/"))
return url + subPath;
else
Expand Down
3 changes: 3 additions & 0 deletions packages/meteor/url_server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if (process.env.ROOT_URL &&
typeof __meteor_runtime_config__ === "object")
__meteor_runtime_config__.ROOT_URL = process.env.ROOT_URL;
if (process.env.ABSOLUTE_URL &&
typeof __meteor_runtime_config__ === "object")
__meteor_runtime_config__.ABSOLUTE_URL = true;
48 changes: 32 additions & 16 deletions packages/webapp/webapp_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ var runWebAppServer = function () {
"// ##RUNTIME_CONFIG##",
"__meteor_runtime_config__ = " +
JSON.stringify(__meteor_runtime_config__) + ";");
var rootUrl = "";
if (process.env.ABSOLUTE_URL) {
rootUrl = __meteor_runtime_config__.ROOT_URL || process.env.ROOT_URL;
}
boilerplateHtml = boilerplateHtml.replace(
/##ROOT_URL##/g,
rootUrl
);

app.use(function (req, res, next) {
if (! appUrl(req.url))
Expand Down Expand Up @@ -283,7 +291,11 @@ var runWebAppServer = function () {
};
};

var bindToProxy = function (proxyConfig) {
var bindToProxy = Meteor._bindToProxy = function (proxyConfig) {

var securePort = proxyConfig.securePort || (proxyConfig.unprivilegedPorts ? 4433 : 443);
var insecurePort = proxyConfig.insecurePort || (proxyConfig.unprivilegedPorts ? 8080 : 80);
var bindPathPrefix = proxyConfig.bindPathPrefix || "";
// XXX also support galaxy-based lookup
if (!proxyConfig.proxyEndpoint)
throw new Error("missing proxyEndpoint");
Expand All @@ -306,10 +318,10 @@ var bindToProxy = function (proxyConfig) {
var myHost = os.hostname();

var ddpBindTo = proxyConfig.unprivilegedPorts ? {
ddpUrl: 'ddp://' + proxyConfig.bindHost + ':4433/',
insecurePort: 8080
ddpUrl: 'ddp://' + proxyConfig.bindHost + ':' + securePort + bindPathPrefix + '/',
insecurePort: insecurePort
} : {
ddpUrl: 'ddp://' + proxyConfig.bindHost + '/'
ddpUrl: 'ddp://' + proxyConfig.bindHost + bindPathPrefix + '/'
};

// This is run after packages are loaded (in main) so we can use
Expand All @@ -331,25 +343,29 @@ var bindToProxy = function (proxyConfig) {
pid: pid,
bindTo: {
host: proxyConfig.bindHost,
port: proxyConfig.unprivilegedPorts ? 8080 : 80
port: insecurePort,
pathPrefix: bindPathPrefix
},
proxyTo: {
host: host,
port: port
}
});
proxy.call('bindHttp', {
pid: pid,
bindTo: {
host: proxyConfig.bindHost,
port: proxyConfig.unprivilegedPorts ? 4433: 443,
ssl: true
},
proxyTo: {
host: host,
port: port
}
if (!proxyConfig.omitSsl) {
proxy.call('bindHttp', {
pid: pid,
bindTo: {
host: proxyConfig.bindHost,
port: securePort,
pathPrefix: bindPathPrefix,
ssl: true
},
proxyTo: {
host: host,
port: port
}
});
}
};

runWebAppServer();
4 changes: 2 additions & 2 deletions tools/app.html.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html##HTML_ATTRIBUTES##>
<head>
{{#each stylesheets}} <link rel="stylesheet" href="{{this}}">
{{#each stylesheets}} <link rel="stylesheet" href="##ROOT_URL##{{this}}">
{{/each}}

<script type="text/javascript">
// ##RUNTIME_CONFIG##
</script>

{{#each scripts}} <script type="text/javascript" src="{{this}}"></script>
{{#each scripts}} <script type="text/javascript" src="##ROOT_URL##{{this}}"></script>
{{/each}}

{{{head_extra}}}
Expand Down

0 comments on commit 213cd94

Please sign in to comment.