tower-archive / tower

UNMAINTAINED - Small components for building apps, manipulating data, and automating a distributed infrastructure.
http://tower.github.io
MIT License
1.79k stars 120 forks source link

Websockets on Heroku #338

Closed matisojka closed 11 years ago

matisojka commented 12 years ago

I have been trying to deploy a Tower app to Heroku.

In /app/app/config/server/bootstrap.coffee there is this:

App.configure ->
  @use 'favicon', Tower.publicPath + '/favicon.png'

  # omitting lots of stuff

  # For "web sockets" on heroku:
    # App.io.configure ->
    #   App.io.set('transports', ['xhr-polling'])

So following the instruction I commented these lines in. Everything looks fine until I deploy and get this error message:

2012-10-18T18:51:24+00:00 app[web.1]: /app/app/config/server/bootstrap.coffee:29
2012-10-18T18:51:24+00:00 app[web.1]:     return this.io.configure(function() {
2012-10-18T18:51:24+00:00 app[web.1]: TypeError: Cannot call method 'configure' of undefined
2012-10-18T18:51:24+00:00 app[web.1]:                    ^
2012-10-18T18:51:24+00:00 app[web.1]:     at null.<anonymous> (/app/app/config/server/bootstrap.coffee:29:20)

What am I missing?

thehydroimpulse commented 12 years ago

Last time I heard heroku didn't support web sockets and you had to change socket.io to use long polling or flash sockets. This might be the issue but the undefined error might be something else. On Oct 18, 2012 12:55 PM, "Mateusz Sojka" notifications@github.com wrote:

I have been trying to deploy a Tower app to Heroku.

In /app/app/config/server/bootstrap.coffee there is this:

App.configure -> @use 'favicon', Tower.publicPath + '/favicon.png' [...] lots of stufff

For "web sockets" on heroku:

# App.io.configure ->
#   App.io.set('transports', ['xhr-polling'])

So following the instruction I commented these lines in. Everything looks fine until I deploy and get this error message:

2012-10-18T18:51:24+00:00 app[web.1]: /app/app/config/server/bootstrap.coffee:29 2012-10-18T18:51:24+00:00 app[web.1]: return this.io.configure(function() { 2012-10-18T18:51:24+00:00 app[web.1]: TypeError: Cannot call method 'configure' of undefined 2012-10-18T18:51:24+00:00 app[web.1]: ^ 2012-10-18T18:51:24+00:00 app[web.1]: at null. (/app/app/config/server/bootstrap.coffee:29:20)

What am I missing?

— Reply to this email directly or view it on GitHubhttps://github.com/viatropos/tower/issues/338.

matisojka commented 12 years ago

The error says that the io variable is undefined, thus why calling configure on it causes the error. Is it possible that the internal Tower API has changed and socket.io isn't defined under App.io anymore?

matisojka commented 12 years ago

And another question, I want to deploy my app as soon as possible to get an idea about how "production ready" Tower actually is. Any recommendations on a hosting service that supports all the technology stack that Tower uses? It doesn't need to be free.

thehydroimpulse commented 12 years ago

@yagooar I'll check up with that error sometime today.

If you want to go hard core, check out amazon ec2. You can get a free micro instance, but remember, it's just a virtual machine (linux). You'll have to install everything yourself. I plan on using Tower in production within the next year (maybe earlier) and I'm going with ec2 at around 10-20 instances to test everything out.

But, if your looking for a PaaS service, then heroku would be your best bet.

matisojka commented 12 years ago

@TheHydroImpulse thanks for the recommendation. Yes I know AWS pretty well but I'm not a big fan of it because of the pricing / capability relation.

Do you know AppFog? They offer PaaS on AWS and Rackspace. I have been using it for Ruby on Rails projects and it is just awesome. They also offer Node.js servers combined with their free option (which is pretty nice). It would be nice to figure out if Tower.js is possible on it (and document it), as it would invite people to check it out in the early days of the framework.

Still, going back to my question, it would be nice if someone who knows more about the internals of Tower could take a look at the io configuration. Thank you for your help once again!

thehydroimpulse commented 12 years ago

I've heard of a lot of PaaS but only used a handful of them. My personal favorite is Pagodabox, albeit only being for PHP at the moment... There support is AMAZING. Hands down the best. I've asked them if there opening support for other platforms, notably node.js and it's their main priority.

But yes, i'll take a look at the internals to the problem here, I've got a bunch of free time today.

lancejpollard commented 11 years ago

@yagooar It looks like that generated code for io needs to be delayed until it's defined:

https://github.com/viatropos/tower/blob/4ff0b9d3a08faf3c8173759a959d3977ea50f7e2/packages/tower-application/server/application.coffee#L186

Try waiting until the next tick:

App.configure ->
  # ...
  # For "web sockets" on heroku:
  process.nextTick ->
    App.io.configure 'production', ->
      App.io.set('transports', ['xhr-polling'])

Heroku doesn't support web sockets so all this is doing is telling socket.io to fall back to ajax polling (https://devcenter.heroku.com/articles/using-socket-io-with-node-js-on-heroku). Amazon is probably the best place (and nodejitsu if it's public yet) to really test out web sockets.