Permalink
Browse files

[api minor] Minor style changes. Support Array of .ca options.

  • Loading branch information...
1 parent 6977d6a commit bc615fb713b678d210dedfebfd9f1e091906beca @indexzero indexzero committed Nov 20, 2013
Showing with 20 additions and 18 deletions.
  1. +16 −14 lib/core.js
  2. +4 −4 test/ecstatic-test.js
View
30 lib/core.js
@@ -54,32 +54,34 @@ core.createServer = function (options) {
// both https and spdy requires same params
//
if (options.https || options.spdy) {
-
- if (options.https && options.spdy){
- throw new Error('You shouldn\'t be using https and spdy simultaneously.')
+ if (options.https && options.spdy) {
+ throw new Error('You shouldn\'t be using https and spdy simultaneously.');
}
- var key, serverOptions, credentials;
-
- if (options.spdy) {
- key = 'spdy';
- } else {
- key = 'https';
- }
+ var serverOptions,
+ credentials,
+ key = !options.spdy
+ ? 'https'
+ : 'spdy';
serverOptions = options[key];
-
if (!serverOptions.key || !serverOptions.cert) {
- throw new Error('Both options.'+key+'.`key` and options.'+key+'.`cert` are required.');
+ throw new Error('Both options.' + key + '.`key` and options.' + key + '.`cert` are required.');
}
credentials = {
- key: fs.readFileSync(serverOptions.key),
+ key: fs.readFileSync(serverOptions.key),
cert: fs.readFileSync(serverOptions.cert)
};
if (serverOptions.ca) {
- credentials.ca = fs.readFileSync(serverOptions.ca);
+ serverOptions.ca = !Array.isArray(serverOptions.ca)
+ ? [serverOptions.ca]
+ : serverOptions.ca
+
+ credentials.ca = serverOptions.ca.map(function (ca) {
+ return fs.readFileSync(ca);
+ });
}
if (options.spdy){
View
8 test/ecstatic-test.js
@@ -5,7 +5,7 @@
* MIT LICENSE
*
*/
-
+
var assert = require('assert'),
ecstatic = require('ecstatic')(__dirname + '/fixtures/static'),
request = require('request'),
@@ -19,11 +19,11 @@ vows.describe('union/ecstatic').addBatch({
before: [
ecstatic
]
- }).listen(8081, this.callback);
+ }).listen(18082, this.callback);
},
"a request to /some-file.txt": {
topic: function () {
- request({ uri: 'http://localhost:8081/some-file.txt' }, this.callback);
+ request({ uri: 'http://localhost:18082/some-file.txt' }, this.callback);
},
"should respond with `hello world`": function (err, res, body) {
assert.isNull(err);
@@ -32,7 +32,7 @@ vows.describe('union/ecstatic').addBatch({
},
"a request to /404.txt (which does not exist)": {
topic: function () {
- request({ uri: 'http://localhost:8081/404.txt' }, this.callback);
+ request({ uri: 'http://localhost:18082/404.txt' }, this.callback);
},
"should respond with 404 status code": function (err, res, body) {
assert.isNull(err);

0 comments on commit bc615fb

Please sign in to comment.