Blame view

node_modules/jayson/examples/tls_example/client.js 856 Bytes
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  var jayson = require(__dirname + '/../..');
  var fs = require('fs')
  var path = require('path')
  
  // Read node's tls documentation for more information about these options:
  // https://nodejs.org/api/tls.html#tls_tls_connect_options_callback
  var options = {
    key: fs.readFileSync(path.resolve(__dirname + '../../../test/fixtures/keys/agent1-key.pem')),
    cert: fs.readFileSync(path.resolve(__dirname + '../../../test/fixtures/keys/agent1-cert.pem')),
  
    // This is necessary only if the client uses the self-signed certificate.
    ca: [ fs.readFileSync(path.resolve(__dirname + '../../../test/fixtures/keys/ca1-cert.pem')) ],
    port: 3000,
    host: 'localhost'
  };
  
  // create a client
  var client = jayson.client.tls(options);
  
  // invoke "add"
  client.request('add', [1, 1], function(err, error, response) {
    if(err) throw err;
    console.log(response); // 2!
  });