|
|
@ -33,7 +33,7 @@ ExpressApp.prototype.start = function(opts, cb) { |
|
|
|
this.app.use(function(req, res, next) { |
|
|
|
res.setHeader('Access-Control-Allow-Origin', '*'); |
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE'); |
|
|
|
res.setHeader('Access-Control-Allow-Headers', 'x-signature,x-identity,X-Requested-With,Content-Type,Authorization'); |
|
|
|
res.setHeader('Access-Control-Allow-Headers', 'x-signature,x-identity,x-client-version,X-Requested-With,Content-Type,Authorization'); |
|
|
|
next(); |
|
|
|
}); |
|
|
|
var allowCORS = function(req, res, next) { |
|
|
@ -104,6 +104,13 @@ ExpressApp.prototype.start = function(opts, cb) { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
function getServer(req, res, cb) { |
|
|
|
var opts = { |
|
|
|
clientVersion: req.header('x-client-version'), |
|
|
|
}; |
|
|
|
return WalletService.getInstance(opts); |
|
|
|
}; |
|
|
|
|
|
|
|
function getServerWithAuth(req, res, cb) { |
|
|
|
var credentials = getCredentials(req); |
|
|
|
if (!credentials) |
|
|
@ -115,6 +122,7 @@ ExpressApp.prototype.start = function(opts, cb) { |
|
|
|
copayerId: credentials.copayerId, |
|
|
|
message: req.method.toLowerCase() + '|' + req.url + '|' + JSON.stringify(req.body), |
|
|
|
signature: credentials.signature, |
|
|
|
clientVersion: req.header('x-client-version'), |
|
|
|
}; |
|
|
|
WalletService.getInstanceWithAuth(auth, function(err, server) { |
|
|
|
if (err) return returnError(err, res, req); |
|
|
@ -123,7 +131,7 @@ ExpressApp.prototype.start = function(opts, cb) { |
|
|
|
}; |
|
|
|
|
|
|
|
router.post('/v1/wallets/', function(req, res) { |
|
|
|
var server = WalletService.getInstance(); |
|
|
|
var server = getServer(req, res); |
|
|
|
server.createWallet(req.body, function(err, walletId) { |
|
|
|
if (err) return returnError(err, res, req); |
|
|
|
res.json({ |
|
|
@ -134,7 +142,7 @@ ExpressApp.prototype.start = function(opts, cb) { |
|
|
|
|
|
|
|
router.post('/v1/wallets/:id/copayers/', function(req, res) { |
|
|
|
req.body.walletId = req.params['id']; |
|
|
|
var server = WalletService.getInstance(); |
|
|
|
var server = getServer(req, res); |
|
|
|
server.joinWallet(req.body, function(err, result) { |
|
|
|
if (err) return returnError(err, res, req); |
|
|
|
|
|
|
|