0

I have been working with Iron Router, and have been under the impression that the routes run on the server. But recently I was reading through the Accounts-Entry code and noticed that, although the routes are defined in "shared", the methods used to detect if the user is signed in only exists under "client".

This lead me to think about where routes actually run. Are they running on the client, server, both? What about "server" routes?

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • As far as the bleeding edge version of iron:router (version 1.0.0-pre1) is concerned, you can find every answer to your questions here : http://eventedmind.github.io/iron-router/#concepts – saimeunt Sep 17 '14 at 15:49

1 Answers1

1

Have a look at the Server Side Routing section of the docs.

Defining routes and configuring the Router is almost identical on the server and the client. By default, routes are created as client routes. You can specify that a route is intended for the server by providing a where property to the route...

So by adding where: 'server' to the route, you allow it to run on the server. The advantage to defining the routes in a shared directory is that the server can then use the Router object to determine paths on the client (useful for things like generating email).

David Weldon
  • 63,632
  • 11
  • 148
  • 146
  • Right, and that is my understanding. But in every example I have seen, most times people have the routes defined in a place where they would be picked up by both the server and client code, but now I am thinking that I should be defining the default "client" routes either in the client folder or using `isClient()` around it, and defining the server routes either in the server folder or with `isServer()` around it. But, is this recommended? – CodeChimp Sep 17 '14 at 23:50
  • We actually define all of our client routes only on the client (in the `client` directory) , and our server routes only on the server. I think that's perfectly reasonable, especially since your client routes may be pretty complex and have all sorts of client-specific code in them anyway. I think our server only needs to know the client-side password reset route, which we just hard-code. – David Weldon Sep 18 '14 at 01:13
  • Out of curiosity, why does the server need to know the password reset route? – CodeChimp Sep 18 '14 at 11:49
  • We customize the email verification and password reset emails, as described [here](http://stackoverflow.com/questions/25375293/return-url-on-verification). – David Weldon Sep 18 '14 at 16:58
  • Good to know. Will probably have to do something similar for this project eventually. Thanks again for your help. – CodeChimp Sep 18 '14 at 19:49