I'm running Meteor 1.1.0.2 on OS X 10.6.8 and, earlier today, I installed IronRouter via meteor add iron:router so I should have the latest version.
I've got this in my routes file:
Router.route('/create_profile',
function () {
var req = this.request;
var res = this.response;
res.end('hello from the server\n');
}
, {where: 'server'}
);
When I hit this URL:
http://localhost:3000/create_profile
I get an in-browser message saying:
Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/create_profile."
If I remove the , {where: 'server'} then it works. Any suggestions what I should look for?
Juan's answer isn't wrong, but he doesn't follow the convention and he doesn't explain why what you did is wrong.
TL;DR; Define your routes inside lib/routes.js.
A server-side route is a route where you serve content loading meteor on the client. In your example you are simply serving a piece of text. The code inside client/ is executed client-side. That means, that it only runs on the client after meteor has been loaded. So when your server-side route is defined, meteor has already been loaded.
Iron-router is somewhat isomorphic. That means, that the same API is available to you both on the client and on the server. So Iron assumes that routes are defined in common code (inside lib/ for an example). When you set the option where to server, iron will ignore the route when the code is run client-side. When that code is run on the server dough, iron installs what are called connectHandlers. It uses the WebApp.connectHandlers.use API. These handlers make it possible, to circumvent the serving of the meteor core.
When you aren't loading the meteor core, your client-side code isn't executed and shared code is only executed on the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With