title: Setting up ssl in heroku using node.js express and socket.io
body: <p>I attempting to create a ssl handled websocket in heroku using express socket.io and node.</p>
  
  <p>I know that heroku handles ssl funky and that in order to not get a H12 request timeout error I need to handle http as well. I have tried a few different methods at approaching the situation and all leave me at a loss. This is my final product, but I get a EADDRINUSE error. I was wondering if anyone has tried this, and if I could see their approach at it, or if anyone could see where I am going wrong in my code.</p>
  
  <p>Please let me know if this is too vague and hopefully I can narrow it down.</p>
  
  <pre><code>class ServerInitializer
    constructor: (port, sslport) -&gt;
      @port = port
      @express = require 'express'
      @http = require 'http'
      @https = require 'https'
      @fs = require 'fs'
      @options = {
            key: @fs.readFileSync(__dirname+'/../../../private/key.pem'),
            cert: @fs.readFileSync(__dirname+'/../../../private/cacert.pem')
      }
      console.log "STARTING SERVER"
      @startExpress()
      @startSocketIO()
      @startStaticService()
  
    startExpress: -&gt;
      console.log " ...preparing express server."
      global.app = @express()
      app.set 'port', 4001
  
    startSocketIO: -&gt;
      console.log " ...preparing http for socket.io"
      if process.env.NODE_ENV == 'production'
        app.listen app.get 'port'
      global.server = @https.createServer(@options, app)
      server.listen port
      @httpserver = @http.createServer(app)
      global.io = require('socket.io').listen(server)
      console.log " ...socket.io listening on port #{port}"
  
    startStaticService: -&gt;
      console.log " ...preparing to serve static assets"
       app.use @express.bodyParser()
      app.use @express.static(__dirname + '/static')
      console.log "..done."
  
  exports.ServerInitializer = ServerInitializer
  </code></pre>