I'm having a weird issue with meteor when deploying to .meteor.com
Everything works locally but when I deploy my app on meteor.com I get the following error for each of my collections for each routes that I have: collectionName "is not defined".
I tried to configure iron-router with waitOn but it didn't help.
My collections definition looks like this(3 server side and one local):
Posts = new Meteor.Collection('posts');
Previews = new Meteor.Collection(null);
betaUsers = new Meteor.Collection('betaUsers');
ipList = new Meteor.Collection('ipList');
//collections/collections.js
My routes look like this:
Router.configure({
layoutTemplate: 'layout',
waitOn: function() { [Meteor.subscribe('betaUsers'), Meteor.subscribe('Posts'), Meteor.subscribe('Previews')] }
});
Router.map(function() {
this.route('jobList', {path: '/', layoutTemplate: 'layout', data: function() { return Posts.find(); }});
this.route('login', {path: '/login', layoutTemplate: 'layout2'});
this.route('submitJob', {path: '/submit', layoutTemplate: 'layout2'});
this.route('previewPost', {path: '/preview', layoutTemplate: 'layout2'});
this.route('landingPage', {path: '/landing/:_id?', data: function() { return betaUsers.findOne(this.params._id);}, layoutTemplate: 'layoutLp'});
this.route('thankYouPage', {path: '/thanks/:_id', data: function() { return betaUsers.findOne(this.params._id);}, layoutTemplate: 'layoutLp'});
});
//server/router.js
I use both autopublish and insecure.
Did anybody have the same issue? I used similar structures for collections definition and subscription in previous apps and never had this problem.
I'm still familiarizing myself with Meteor so it's probably a stupid mistake on my side ! Thank you ! I can provide further info.
I simply solved the problem by moving the /collections directory inside the /lib directory. The routes where I provide the data (which are in the /lib directory) were being executed before the collections were defined.
If somebody can explain why my old architecture (separate /lib and /collections ) works locally and not remotely it could still be useful I think. Thanks
Related
I recently updated my meteor project and whenever i try to run my project i got this :
Router.route('/', function () {
this.render('Home', {
data: function () { return Items.findOne({_id: this.params._id}); }
});
});
this is my route that should direct the user to "main" template
Router.route('/', {
template: 'main'
});
i used to get similar problem when i first added iron:router package, and the reason was because i haven't implemented it. I believe the way i should implement it is different after the update. please correct me if am wrong
Your router file needs to be included above or in a folder above your client and server folders. It's just there, if router is not contained above client and server than meteor does not digest it properly for the function it serves.
Short answer:
Put router.js where-ever it is that you start your meteor application.
(as opposed to .\client or .\server)
How you configure main template:
Router.configure({
layoutTemplate:'yourMainTemplateName' //main template should have {{> yield}} inside HTML which tells iron:router where to render templates per route
});
Route configuration:
Router.route('/', function () {
this.render('homeTemplateName');
});
Update your question with your new codes if it doesn't work.
I would like to change the splash message of Iron Router failure .Instead of "Organize Your Meteor Application" ,add something user friendly.How to start with this issue ??
It is hard coded here in iron:router repo.
You can fork it and change this line to yours.
But why do you need this? Line 54 here can give you the idea of how iron:router uses your templates.
Router.prototype.lookupNotFoundTemplate = function () {
if (this.options.notFoundTemplate)
return this.options.notFoundTemplate;
return (this.routes.length === 0) ? NO_ROUTES_TEMPLATE : DEFAULT_NOT_FOUND_TEMPLATE;
};
Only if you don't have any routes defined and no config for notFoundTemplate, you will see such message, define it via router config.
Router.configure({
layoutTemplate: 'layout',
notFoundTemplate: 'pageNotFound'
});
When I start the Meteor server and navigate to my default route, I see the AppLoading template inside MainLayout (as expected), but the main template never loads even after the subscription is loaded.
I've got a really simple routes.js file (below)
autopublish is still turned on.
I seeded the db and can confirm in the browser console that the subscription is there, and there are items in my Services collection.
Probably missing something really simple here.
/*===================
CONFIGURE DEFAULTS
====================*/
Router.configure({
layoutTemplate: 'MainLayout',
loadingTemplate: 'AppLoading',
notFoundTemplate: 'NotFound'
});
/*===================
CONFIGURE ROUTES
====================*/
Router.route('/', { // DEFAULT ROUTE
name: 'main',
template: 'Main',
waitOn: function() {
return Meteor.subscribe('services');
},
data: function() {
return Services.find();
}
});
I'm guessing you do not have a publication? The client is waiting for a "ready" notification from the publication and is not receiving it, hence nothing is loaded. Remove autopublish and start writing publications.
The autopublish package literally just copies the server DB to the client. You can't subscribe to anything if you do not actually have any publications.
When I hit a route that doesn't exist on my Meteor app that uses IR, I get a 200 response with an HTML that (when rendered on a browser) displays a js error on console saying that No route found for path: "/aRoute".
How can a make it return 404?
There don't seem to be a correct (or even working?) way of handling real 404's right now. See this issue for example: https://github.com/EventedMind/iron-router/issues/1055
Even when you try ways which should work, you'll still end up with a 200 status code. Like this code below which should work:
this.route( 'pageNotFound', {
path: '/(.*)',
where: 'server',
action: function() {
this.response.writeHead(404);
this.response.end( html );
}
});
I find this much easier way to show page not found. In router.js
Router.configure({
layoutTemplate: "layout",
loadingTemplate: "loading",
notFoundTemplate: "notFound"
})
Here "notFound" could be any template where you want to show 404 error
this.route('template404', {
path: '/*'
}
Use it at the end of your Router.map, cause this catches every value - if you use at the begining every path will be caught to this
Of course you can make it more complex, for example:
this.route('template404', {
path: '/posts/*'
}
Yesterday I updated meteor and my meteorite packages to their latest versions. Today, iron router is not behaving. When I navigate to a parameterized route, the parameter is not loaded. What gives? I have looked at the documentation for iron-router, and it still specifies the same scheme I was using before.
This is the routes file I have created
Router.map(function() {
this.route('home', {
path: '/'
});
this.route('list', {
path: '/:_id',
waitOn: function() {
return Meteor.subscribe('lists')
},
data: function() {
var list = Lists.findOne({
_id: this.params._id
});
Session.set('listId', list._id);
return list;
}
});
});
When I load a page to http://localhost/1234 the path in iron router is correctly set to /1234 but it does not recognize the last bit as a parameter.
I am afraid that what is empty is not your this.params object but rather the list document, at least for the first time the route is being executed. This is caused, of course, by the latency related to fetching server data.
You may be thinking that it shouldn't happen because you have used the waitOn hook. But for this to work you would also need to do two other things:
Router.onBeforeAction('loading');
and define the loading template:
Router.configure({
loadingTemplate: 'someTemplateName'
});
so please update if you haven't done it already.