Fix the handling of DELETE and PUT calls, and stop unintentional deserialization
of JSON instead of passing it through as an opaque string.
This commit is contained in:
parent
df9677efe5
commit
991f5cabdc
@ -12,6 +12,7 @@ const mod_sdcauth = require('smartdc-auth');
|
|||||||
let CONFIG = {};
|
let CONFIG = {};
|
||||||
let PRIVATE_KEY = '';
|
let PRIVATE_KEY = '';
|
||||||
let CLOUDAPI = {};
|
let CLOUDAPI = {};
|
||||||
|
let CLOUDAPI_HOST = '';
|
||||||
let SIGNER = {};
|
let SIGNER = {};
|
||||||
|
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ let SIGNER = {};
|
|||||||
function proxy(req, res, cb) {
|
function proxy(req, res, cb) {
|
||||||
// return data from cloudapi to the client caller
|
// return data from cloudapi to the client caller
|
||||||
function proxyReturn(err, _, res2, data) {
|
function proxyReturn(err, _, res2, data) {
|
||||||
if (err && !res2.statusCode) {
|
if (err && !res2) {
|
||||||
res.send(500);
|
res.send(500);
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
@ -53,6 +54,7 @@ function proxy(req, res, cb) {
|
|||||||
return (cb(err));
|
return (cb(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headers.host = CLOUDAPI_HOST;
|
||||||
headers.authorization = authz;
|
headers.authorization = authz;
|
||||||
|
|
||||||
const opts = {
|
const opts = {
|
||||||
@ -62,11 +64,11 @@ function proxy(req, res, cb) {
|
|||||||
|
|
||||||
// make the call to cloudapi
|
// make the call to cloudapi
|
||||||
switch (req.method) {
|
switch (req.method) {
|
||||||
case 'GET': CLOUDAPI.get(opts, proxyReturn); break;
|
case 'GET': CLOUDAPI.get(opts, proxyReturn); break;
|
||||||
case 'DEL': CLOUDAPI.del(opts, proxyReturn); break;
|
case 'DELETE': CLOUDAPI.del(opts, proxyReturn); break;
|
||||||
case 'HEAD': CLOUDAPI.head(opts, proxyReturn); break;
|
case 'HEAD': CLOUDAPI.head(opts, proxyReturn); break;
|
||||||
case 'POST': CLOUDAPI.post(opts, req.body, proxyReturn); break;
|
case 'POST': CLOUDAPI.post(opts, req.body, proxyReturn); break;
|
||||||
case 'PUT': CLOUDAPI.del(opts, req.body, proxyReturn); break;
|
case 'PUT': CLOUDAPI.put(opts, req.body, proxyReturn); break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -134,12 +136,12 @@ function main() {
|
|||||||
CLOUDAPI = mod_restify.createStringClient({
|
CLOUDAPI = mod_restify.createStringClient({
|
||||||
url: CONFIG.urls.cloudapi,
|
url: CONFIG.urls.cloudapi,
|
||||||
agent: new mod_cueball.HttpsAgent({
|
agent: new mod_cueball.HttpsAgent({
|
||||||
spares: 4,
|
spares: 0,
|
||||||
maximum: 10,
|
maximum: 4,
|
||||||
recovery: {
|
recovery: {
|
||||||
default: {
|
default: {
|
||||||
timeout: 2000,
|
timeout: 2000,
|
||||||
retries: 5,
|
retries: 2,
|
||||||
delay: 250,
|
delay: 250,
|
||||||
maxDelay: 1000
|
maxDelay: 1000
|
||||||
}
|
}
|
||||||
@ -147,6 +149,8 @@ function main() {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CLOUDAPI_HOST = CONFIG.urls.cloudapi.split('/')[2];
|
||||||
|
|
||||||
// prepare HTTP server
|
// prepare HTTP server
|
||||||
const options = {
|
const options = {
|
||||||
key: mod_fs.readFileSync(CONFIG.server.key),
|
key: mod_fs.readFileSync(CONFIG.server.key),
|
||||||
@ -155,7 +159,7 @@ function main() {
|
|||||||
|
|
||||||
const server = mod_restify.createServer(options);
|
const server = mod_restify.createServer(options);
|
||||||
server.use(mod_restify.authorizationParser());
|
server.use(mod_restify.authorizationParser());
|
||||||
server.use(mod_restify.bodyParser());
|
server.use(mod_restify.bodyReader());
|
||||||
|
|
||||||
// where to server static content from
|
// where to server static content from
|
||||||
server.get(/^\/static.*/, mod_restify.plugins.serveStatic({
|
server.get(/^\/static.*/, mod_restify.plugins.serveStatic({
|
||||||
|
Reference in New Issue
Block a user