diff --git a/README.md b/README.md index e18f0e4..ee658e0 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Usage - new style with multiple app files: Commands: push : Push app once to server. + options + -3 : allow connections via SSL V3 sync : Push app then watch local files for changes. boiler : Create a boiler project. serve : Serve couchapp from development webserver diff --git a/bin.js b/bin.js index 431ed5e..543040c 100755 --- a/bin.js +++ b/bin.js @@ -172,7 +172,7 @@ if (process.mainModule && process.mainModule.filename === __filename) { if (command == 'boiler') { boiler(app); } else { - couchapp.createApp(require(abspath(app)), couch, function (app) { + couchapp.createApp(require(abspath(app)), couch, parsePushOptions(), function (app) { if (command == 'push') app.push() else if (command == 'sync') app.sync() else if (command == 'serve') serve(app); @@ -183,6 +183,18 @@ if (process.mainModule && process.mainModule.filename === __filename) { } +function parsePushOptions() { + var options = {}; + + while(arg = process.argv.shift()){ + if(arg == '-3'){ + options.sslv3 = true; + } + } + + return options; +} + // Start a development web server on app function serve(app) { var url = require('url'); diff --git a/main.js b/main.js index 4e0dc51..3226200 100644 --- a/main.js +++ b/main.js @@ -111,7 +111,15 @@ function copy (obj) { } -function createApp (doc, url, cb) { +function createApp (doc, url, options, cb) { + if (cb === undefined) { + cb = options; + } + + if (options === undefined) { + options = {}; + } + var app = {doc:doc} app.fds = {}; @@ -135,6 +143,14 @@ function createApp (doc, url, cb) { app.doc.attachments_md5 = app.doc.attachments_md5 || {} app.doc._attachments = app.doc._attachments || {} } + + function requestOptions(opts) { + if (options.sslv3) { + opts.secureProtocol = 'SSLv3_method'; + } + + return opts; + } var push = function (callback) { console.log('Serializing.') @@ -143,14 +159,14 @@ function createApp (doc, url, cb) { delete doc.__attachments; var body = JSON.stringify(doc) console.log('PUT '+url.replace(/^(https?:\/\/[^@:]+):[^@]+@/, '$1:******@')) - request({uri:url, method:'PUT', body:body, headers:h}, function (err, resp, body) { + request(requestOptions({uri:url, method:'PUT', body:body, headers:h}), function (err, resp, body) { if (err) throw err; if (resp.statusCode !== 201) { throw new Error("Could not push document\nCode: " + resp.statusCode + "\n"+body); } app.doc._rev = JSON.parse(body).rev console.log('Finished push. '+app.doc._rev) - request({uri:url, headers:h}, function (err, resp, body) { + request(requestOptions({uri:url, headers:h}), function (err, resp, body) { body = JSON.parse(body); app.doc._attachments = body._attachments; if (callback) callback() @@ -309,7 +325,7 @@ function createApp (doc, url, cb) { if (url.slice(url.length - _id.length) !== _id) url += '/' + _id; - request({uri:url, headers:h}, function (err, resp, body) { + request(requestOptions({uri:url, headers:h}), function (err, resp, body) { if (err) throw err; if (resp.statusCode == 404) app.current = {}; else if (resp.statusCode !== 200) throw new Error("Failed to get doc\n"+body)