Question

I have created a simple Iron-Router test app that was meant to help me get a handle on server side routing (in addition to other things, but I am struggling with server side routing right now). I am currently using the blaze-integration branch in this project. My route looks like this (obviously, this is in CoffeeScript):

Router.map ->
  @route 'something',
    path: '/something'
    where: 'server'
    before: ->
      console.log @
    action: ->
      @response.writeHead 200, {'Content-Type': 'text/html'}
      @response.end 'hello from server!'

This route fails in my app, but in different ways depending on where I put the route. If I define this in it's own router.coffee within a server folder of my app, I get the following error when I trigger the route by trying to navigate to the path /something:

W20140306-16:49:25.347(-5)? (STDERR) TypeError: Object [object Object] has no method 'run'
W20140306-16:49:25.350(-5)? (STDERR)     at Utils.extend.run (packages/iron-router/lib/server/router.js:62)
W20140306-16:49:25.350(-5)? (STDERR)     at next (packages/iron-router/lib/router.js:272)
W20140306-16:49:25.352(-5)? (STDERR)     at IronRouter.dispatch (packages/iron-router/lib/router.js:278)
W20140306-16:49:25.352(-5)? (STDERR)     at packages/iron-router/lib/server/router.js:37

I'm not sure what this is, or how to resolve this issue. My attempt was to just put this exact same route where I defined all my other routes, in the irtest.coffee file in the client folder. If I do that, however, I don't get an error, but the page just continuously reloads.

So I guess my question is two-fold:

  1. Why would my server route be malfunctioning in each of the above situations?
  2. Where would be the most 'correct' place to define these server side routes?

Any other pointers are welcome, too! I'm pretty new to this stuff!

PS The full project can be seen and cloned here.

EDIT In accordance with Christian's tips in the comments, I split the routes into their own file called router.coffee located in the app's root. After doing this and trying to access /something, I get the same TypeError as I did before, when the routes were placed in the client and the server folder respectively.

Was it helpful?

Solution

It works for me. Here is what I did:

  1. meteor create test
  2. cd test
  3. created router.coffee with your code
  4. mrt add iron-router
  5. meteor add coffeescript
  6. reloaded the page and got "hello from server" and an elaborate printout on the (server) console

It seems the problem is somewhere else in your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top