Allowing passing in a default DDP endpoint as an environment variable.

This commit is contained in:
Nick Martin
2012-06-22 21:01:42 -07:00
parent a39aabc25c
commit a248f0ff28
3 changed files with 43 additions and 14 deletions

View File

@@ -4,6 +4,11 @@
{{#each stylesheets}} <link rel="stylesheet" href="{{this}}">
{{/each}}
<script type="text/javascript">
__meteor_runtime_config__ = {};
// ##RUNTIME_CONFIG##
</script>
{{#each scripts}} <script type="text/javascript" src="{{this}}"></script>
{{/each}}

View File

@@ -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) {

View File

@@ -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);
});
})();