Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
24 changes: 20 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -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.')
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down