Skip to content

Commit

Permalink
add() should not be called within Meteor.startup() on server-side, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvaingi committed Apr 16, 2013
1 parent 32e377c commit 4838a36
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions examples/simple-routed-app/simple-routed-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if (Meteor.is_client) {
// so you can know if you've successfully in-browser browsed
console.log('Started at ' + location.href);
});

Meteor.Router.add({
'/': 'home',

Expand All @@ -26,16 +26,17 @@ if (Meteor.is_client) {
}
});

Meteor.Router.filter('requireLogin', {only: 'welcome'})
Meteor.Router.filter('requireLogin', {only: 'welcome'});

Template.sign_in.events = {
'submit form': function(e) {
e.preventDefault();
Session.set('username', $(e.target).find('[name=username]').val())
Session.set('username', $(e.target).find('[name=username]').val());
}
}
};

Template.welcome.username = function() { return Session.get('username'); };

Template.welcome.username = function() { return Session.get('username'); }
Template.welcome.events = {

'submit form': function(event, template) {
Expand All @@ -49,34 +50,33 @@ if (Meteor.is_client) {
e.preventDefault();
Session.set('username', false);
}
}
};

Template.post.helpers({
id: function() { return Session.get('postId'); }
})
});
}

if (Meteor.isServer) {
Meteor.Router.add({
'/test-endpoint': 'SOME DATA!',
'/second-test-endpoint': function() {
console.log(this.request.body);
return 'foo';
}
});

Meteor.Router.add({
'/posts/:id.xml': function(id) {
return Posts.findOne(id).foo;
}
});

// don't actually publish this
var Posts = new Meteor.Collection('posts');
Meteor.startup(function() {
if (Posts.find().count() === 0) {
console.log('added Post: ' + Posts.insert({foo: 'bar'}));
}


Meteor.Router.add({
'/test-endpoint': 'SOME DATA!',
'/second-test-endpoint': function() {
console.log(this.request.body);
return 'foo';
}
})

Meteor.Router.add({
'/posts/:id.xml': function(id) {
return Posts.findOne(id).foo;
}
});
});
}

0 comments on commit 4838a36

Please sign in to comment.