diff --git a/app/lib/app.html.in b/app/lib/app.html.in
index ac617bd252..0149601a24 100644
--- a/app/lib/app.html.in
+++ b/app/lib/app.html.in
@@ -4,6 +4,11 @@
{{#each stylesheets}}
{{/each}}
+
+
{{#each scripts}}
{{/each}}
diff --git a/app/server/server.js b/app/server/server.js
index 42e6833373..0339170f6b 100644
--- a/app/server/server.js
+++ b/app/server/server.js
@@ -47,7 +47,19 @@ var supported_browser = function (user_agent) {
// return !(agent.family === 'IE' && +agent.major <= 5);
};
-var run = function (bundle_dir) {
+// add any runtime configuration options needed to app_html
+var runtime_config = function (app_html) {
+ var insert = '';
+ if (process.env.DEFAULT_DDP_ENDPOINT)
+ insert += "__meteor_runtime_config__.DEFAULT_DDP_ENDPOINT = '" +
+ process.env.DEFAULT_DDP_ENDPOINT + "';";
+
+ app_html = app_html.replace("// ##RUNTIME_CONFIG##", insert);
+
+ return app_html;
+};
+
+var run = function () {
var bundle_dir = path.join(__dirname, '..');
// check environment
@@ -63,9 +75,11 @@ var run = function (bundle_dir) {
app.use(gzippo.staticGzip(static_cacheable_path, {clientMaxAge: 1000 * 60 * 60 * 24 * 365}));
app.use(gzippo.staticGzip(path.join(bundle_dir, 'static')));
- var app_html = fs.readFileSync(path.join(bundle_dir, 'app.html'));
+ var app_html = fs.readFileSync(path.join(bundle_dir, 'app.html'), 'utf8');
var unsupported_html = fs.readFileSync(path.join(bundle_dir, 'unsupported.html'));
+ app_html = runtime_config(app_html);
+
app.use(function (req, res) {
// prevent favicon.ico and robots.txt from returning app_html
if (_.indexOf(['/favicon.ico', '/robots.txt'], req.url) !== -1) {
diff --git a/packages/livedata/client_convenience.js b/packages/livedata/client_convenience.js
index 60f8d07a29..dc40ead44e 100644
--- a/packages/livedata/client_convenience.js
+++ b/packages/livedata/client_convenience.js
@@ -1,14 +1,24 @@
-_.extend(Meteor, {
- default_connection: Meteor.connect('/', true /* restart_on_update */),
+(function () {
+ // By default, try to connect back to the same endpoint as the page
+ // was served from.
+ var ddp_endpoint = '/';
+ if (__meteor_runtime_config__.DEFAULT_DDP_ENDPOINT)
+ ddp_endpoint = __meteor_runtime_config__.DEFAULT_DDP_ENDPOINT;
- refresh: function (notification) {
- }
-});
+ _.extend(Meteor, {
+ default_connection: Meteor.connect(ddp_endpoint,
+ true /* restart_on_update */),
-// Proxy the public methods of Meteor.default_connection so they can
-// be called directly on Meteor.
-_.each(['subscribe', 'methods', 'call', 'apply', 'status', 'reconnect'],
- function (name) {
- Meteor[name] = _.bind(Meteor.default_connection[name],
- Meteor.default_connection);
- });
+ refresh: function (notification) {
+ }
+ });
+
+ // Proxy the public methods of Meteor.default_connection so they can
+ // be called directly on Meteor.
+ _.each(['subscribe', 'methods', 'call', 'apply', 'status', 'reconnect'],
+ function (name) {
+ Meteor[name] = _.bind(Meteor.default_connection[name],
+ Meteor.default_connection);
+ });
+
+})();