title: Angular + Node.js HTTP & HTTPS (SSL)
body: <p>I want to use https for the post requests in my payment view. I stumbled over diff tutorials and now my setup is the following (and I still don't get it running):</p>
  
  <h1>Certificates</h1>
  
  <p>I generated certificates for my development environment using this tutorial:
  <a href="http://greengeckodesign.com/blog/2013/06/15/creating-an-ssl-certificate-for-node-dot-js/" rel="nofollow noreferrer">http://greengeckodesign.com/blog/2013/06/15/creating-an-ssl-certificate-for-node-dot-js/</a></p>
  
  <h1>Node.js</h1>
  
  <p>I followed answer #2 to setup the http and https server in node:
  <a href="https://stackoverflow.com/questions/8355473/listen-on-http-and-https-for-a-single-express-app">Listen on HTTP and HTTPS for a single express app</a></p>
  
  <p>It looks like that:</p>
  
  <pre><code>environment = require('./config/config.js')()
  
  express  = require('express')
  bodyParser = require('body-parser')
  app      = express()
  portHTTP     = process.env.PORT || 61361
  portHTTPS = 3030
  mongoose = require('mongoose')
  morgan       = require('morgan')
  http = require('http')
  https = require('https')
  socket = require('socket.io')
  
  #SSL Server
  fs = require('fs')
  sslOptions = {
    key: fs.readFileSync(__dirname + '/config/ssl/server.key'),
    cert: fs.readFileSync(__dirname + '/config/ssl/server.crt'),
    ca: fs.readFileSync(__dirname + '/config/ssl/ca.crt'),
    requestCert: true,
    rejectUnauthorized: false
  }
  
  #Database
  configDB = require('./config/database.js')(environment)
  mongoose.connect(configDB.url,{auth:{authdb:configDB.authdb}}, (err)-&gt;
    if (err)
      console.log(err)
  )
  db = mongoose.connection
  db.on('error', console.error.bind(console, 'connection error:'))
  db.once('open', () -&gt;
    console.log "Database established"
  )
  
  #Express Application
  app.use(morgan('dev'))# log every request to the console
  app.use(bodyParser.urlencoded({ extended: true }))
  app.use(bodyParser.json())
  
  rootPath = __dirname + '/../../'
  app.use('/bower_components', express.static(rootPath + 'bower_components'))
  app.use('/partials', express.static(__dirname + '/../partials'))
  
  # Routes
  require('./node/routes.js')(app, db) # load our routes and pass in our app and fully configured passport
  
  # Launch the application
  https.createServer(sslOptions,app).listen(portHTTPS, () -&gt;
    console.log("Secure Express server listening on port #{portHTTPS}")
  )
  http.createServer(app).listen(portHTTP)
  io = socket.listen(https)
  
  #app.listen(portHTTP)
  console.log('Unsecure Express server listening on port #{portHTTP} environment: #{environment}')
  </code></pre>
  
  <h1>Angularjs</h1>
  
  <p>I installed the angular module:
  <a href="https://github.com/btford/angular-socket-io" rel="nofollow noreferrer">https://github.com/btford/angular-socket-io</a></p>
  
  <p>And added it to my index.coffee</p>
  
  <pre><code>angular.module "app", [lots of dependencies, 'btford.socket-io', 'myCodeService']
    .config ($stateProvider, $urlRouterProvider) -&gt;
      ...states...
    .factory('mySocket', (socketFactory) -&gt;
      return socketFactory({
        ioSocket: io.connect('https://localhost:3030/',{secure: true})
        #ioSocket: io.connect('https://cdn.socket.io/socket.io-1.3.4.js',{secure: true})
      })
    )
  </code></pre>
  
  <p>I added the two script tags into my index.html</p>
  
  <pre><code>&lt;script src="../bower_components/angular-socket-io/socket.js"&gt;&lt;/script&gt;
  &lt;script src="http://localhost:3030/socket.io/socket.io.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <h1>Gulp Setup</h1>
  
  <p>And I serve in gulp with nodemon and browsersync</p>
  
  <pre><code>gulp.task('serve',['watch'], function(cb){
    var called = false;
    return nodemon({
      script: paths.tmp + '/serve/server.js',
      watch: [paths.src + '/node', paths.src + '/config'],
      ext: 'coffee',
      tasks: ['templateCache', 'partials_tmp'],
      env: { 'NODE_ENV': 'development' } ,
      nodeArgs: ['--debug=9999']
    })
    ....
  
   function browserSyncInit(files, browser) {
    browser = browser === undefined ? 'default' : browser;
    browserSync.instance = browserSync.init(files, {
      startPath: '/#/',
      browser: browser,
      proxy: "http://localhost:61361"
    });
  }
  </code></pre>
  
  <p>I get an empty response from socket.io and I don't see anything in my browser which bugs me to accept the certificate.</p>
  
  <p>There is an https option for browsersync but I don't really know how to split the traffic/ or if this is done automatically in node.js.</p>