senecajs / seneca-transport

Seneca micro-services message transport over TCP and HTTP.
MIT License
63 stars 45 forks source link

Adding HTTPS functionality for type web/http Seneca microservices. #85

Closed cesarecontini closed 8 years ago

cesarecontini commented 8 years ago

To enable HTTPS make sure to set the protocol option to 'https' and in the listen function set the serverOptions object with the keyPemPath and the certPemPath keys with string paths leading to the SSL's pem key & certificate files

var seneca = require('seneca')

seneca()
  .use(color)
  .listen(
    type: 'http',
    port: '8000',
    host: 'localhost',
    protocol: 'https',
    serverOptions : {
      keyPemPath : './key.pem',
      certPemPath : './certificate.pem'
    }
  )

seneca()
  .client({
    type: 'http',
    port: '8000',
    host: 'localhost',
    protocol: 'https'
  })
  .act('color:red')
geek commented 8 years ago

Looks good, can you also add a test for the new functionality?

cesarecontini commented 8 years ago

Hello @geek , do you want me to add a test file in the test folder?

Cheers, Cesare

geek commented 8 years ago

@cesarecontini feel free to add tests to the http.test.js file. In wreck we have a few examples of some https tests you can borrow from: https://github.com/hapijs/wreck/blob/0a9e799c26104f93042ae02b62cd4fc69621029d/test/index.js#L289-L312

cesarecontini commented 8 years ago

Hello @geek I have added some tests in the http.test.js file (running a seneca server & client & Wreck client). Of course to test it locally the seneca service/server will need a certificate, so I have added instructions in the test folder readme file (https://github.com/cesarecontini/seneca-transport/tree/master/test) as following:

server & client running on https://127.0.0.1:8000 (https)

Create a folder 'ssl' within 'test' folder (ie ./test/ssl) Create a self-signed certificate with OpenSSL by running within the ./ssl folder:

$ openssl genrsa -out key.pem 2048 $ openssl req -new -key key.pem -out csr.pem $ openssl req -x509 -days 365 -key key.pem -in csr.pem -out cert.pem

Then from within ./test folder run:

$ node readme-color-web-https.js

Cheers, Cesare

geek commented 8 years ago

@cesarecontini thank you... after you fix up the linting issues then it should be good to go

cesarecontini commented 8 years ago

Hi @geek where do I get the latest lint error page for this? I can't find it :(

cesarecontini commented 8 years ago

Hello @geek sorry I didn't realise the project was using ESlint. I should have fixed those errors for the files I have edited/created for this. Regards, Cesare

cesarecontini commented 8 years ago

Hi @geek how's things? Is there any update with this?

Cheers C.

geek commented 8 years ago

@cesarecontini sure thing... take a look at https://travis-ci.org/senecajs/seneca-transport/jobs/116380966

We still support node 0.10 and 0.12

cesarecontini commented 8 years ago

Hello @geek, thanks for getting back to me!

I've reverted the ES6 function declaration so it is now compatible to older node version.

If I run the npm test command, it will basically pass the tests on my local machine because I have got an 'ssl' folder with the ssl self-signed certificate and key needed by the Seneca service to run on https. I have not pushed the 'ssl' folder in github. Is this going to be an issue? Or tests must pass on the travis CI anyway?

If so could you suggest me a way to go around the problem in travis CI?

Regards, Cesare

cesarecontini commented 8 years ago

thanks @geek I will crack on it... speak you soon. Cheers, C.

cesarecontini commented 8 years ago

Hello @geek I have made the changes (i.e. removed the fs loading dependency for ssl certificate/key files from seneca-transport plugin) & amended test files as suggested. The build job is now run fine ;) Cheers & many thanks, Cesare

geek commented 8 years ago

@cesarecontini nicely done, I will get this published soon and added to seneca.

cesarecontini commented 8 years ago

Hello @geek, good stuff thank you ;)

Just another thing, I've noticed that the main seneca npm package still refers to the old 1.1.1 seneca-transport version so unless you explicitly specify the newest version in your package.json file i.e. ... "seneca": "^1.4.0", "seneca-transport": "^1.2.0" ... version 1.1.1 will be installed from a brand new seneca installation.