Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
let body = (yield httpReq).body;
if (subsegment) {
subsegment.close();
}
resolve(body);
} catch (err) {
if (subsegment) {
subsegment.close(err);
}
reject(err);
}
});
// the current sub/segment
let segment = AWSXRay.getSegment();
AWSXRay.captureAsyncFunc("getting restaurants", f, segment);
});
}
app.get('/', function(req, res) {
var seg = XRay.getSegment();
seg.addAnnotation('service', 'service-b-request');
var reqData = queryString.stringify(req.body);
var options = {
host: apiCNAME,
port: '80',
path: '/create',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(reqData)
}
};
// Set up the request
app.get('/', function(req, res) {
var seg = XRay.getSegment();
seg.addAnnotation('service', 'service-b-request');
var reqData = queryString.stringify(req.body);
var options = {
host: apiCNAME,
port: '80',
path: '/create',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(reqData)
}
};
// Set up the request
app.get('/', function(req, res) {
var seg = XRay.getSegment();
seg.addAnnotation('service', 'service-b-request');
var reqData = queryString.stringify(req.body);
var options = {
host: apiCNAME,
port: '80',
path: '/create',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(reqData)
}
};
// Set up the request
var calcid = req.body.calcid;
console.log("=====================================");
console.log("Calculator entry point...");
if (typeof calcid == "undefined") {
calcid = shortid.generate();
console.log(`generating new calcid: ${calcid}`);
}
else {
console.log(`calcid supplied: ${calcid}`);
}
console.log(`calcid: ${calcid}, infix: ${infix}`);
var seg = xray.getSegment();
seg.addAnnotation('calcid', calcid);
const postData = querystring.stringify({
'calcid': calcid,
'expression': infix
});
const options = {
hostname: '172.19.0.200',
port: 9090,
path: '/api/postfix/',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
router.post("/postfix", function(req, res) {
var calcid = req.body.calcid;
var infix = req.body.expression;
var seg = xray.getSegment();
seg.addAnnotation('calcid', calcid);
console.log(`${serviceName}->calcid: ${calcid}, infix: ${infix}`);
var postfix = mathsolver.infixToPostfix(infix).trim();
console.log(`${serviceName}->calcid: ${calcid}, postfix: ${postfix}`);
res.write(postfix);
var responseCode = 200;
var random = Math.random();
//randomize response code
if (random < 0.8) {
//GREEN
responseCode = 200;
} else if (random < 0.9) {
//ORANGE
router.get("/divide", function(req, res) {
console.log("dividing...")
var calcid = req.query.calcId;
var left = req.query.leftOp;
var right = req.query.rightOp;
var seg = xray.getSegment();
seg.addAnnotation('calcid', calcid);
var result = Number(left) / Number(right);
console.log(`${left}/${right}=${result}`);
res.write(result.toString());
seg.addMetadata("left", left);
seg.addMetadata("right", right);
seg.addMetadata("operator", "/");
seg.addMetadata("result", result);
var responseCode = 200;
var random = Math.random();
//randomize response code
if (random < 0.8) {
router.get("/subtract", function(req, res) {
console.log("subtracting...");
var calcid = req.query.calcId;
var left = req.query.leftOp;
var right = req.query.rightOp;
var seg = xray.getSegment();
seg.addAnnotation('calcid', calcid);
var result = Number(left) - Number(right);
console.log(`${left}-${right}=${result}`);
res.write(result.toString());
seg.addMetadata("left", left);
seg.addMetadata("right", right);
seg.addMetadata("operator", "-");
seg.addMetadata("result", result);
var responseCode = 200;
var random = Math.random();
//randomize response code
if (random < 0.8) {
router.get("/multiply", function(req, res) {
console.log("multiplying...");
var calcid = req.query.calcId;
var left = req.query.leftOp;
var right = req.query.rightOp;
var seg = xray.getSegment();
seg.addAnnotation('calcid', calcid);
var result = Number(left) * Number(right);
console.log(`${left}*${right}=${result}`);
res.write(result.toString());
seg.addMetadata("left", left);
seg.addMetadata("right", right);
seg.addMetadata("operator", "*");
seg.addMetadata("result", result);
var responseCode = 200;
var random = Math.random();
//randomize response code
if (random < 0.8) {
router.get("/add", function(req, res) {
console.log("adding...");
var calcid = req.query.calcId;
var left = req.query.leftOp;
var right = req.query.rightOp;
var seg = xray.getSegment();
seg.addAnnotation('calcid', calcid);
var result = Number(left) + Number(right);
console.log(`${left}+${right}=${result}`);
res.write(result.toString());
seg.addMetadata("left", left);
seg.addMetadata("right", right);
seg.addMetadata("operator", "+");
seg.addMetadata("result", result);
var responseCode = 200;
var random = Math.random();
//randomize response code
if (random < 0.8) {