When trying to run the RPC commands for the methods we get, I can't seem to figure out the issue. It was working on local but not on the live linux server.
TypeError: Cannot read property 'method' of undefined at C:\ssc-exchange-tranactions\app.js:23:13 at Layer.handle [as handle_request] (C:\ssc-exchange-tranactions\node_modules\express\lib\router\layer.js:95:5) at next (C:\ssc-exchange-tranactions\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\ssc-exchange-tranactions\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\ssc-exchange-tranactions\node_modules\express\lib\router\layer.js:95:5) at C:\ssc-exchange-tranactions\node_modules\express\lib\router\index.js:281:22 at Function.process_params (C:\ssc-exchange-tranactions\node_modules\express\lib\router\index.js:335:12) at next (C:\ssc-exchange-tranactions\node_modules\express\lib\router\index.js:275:10) at jsonParser (C:\ssc-exchange-tranactions\node_modules\body-parser\lib\types\json.js:119:7) at Layer.handle [as handle_request] (C:\ssc-exchange-tranactions\node_modules\express\lib\router\layer.js:95:5)
const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
const port = 5000;
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
const dsteem = require('dsteem');
const client = new dsteem.Client('https://api.site.com');
app.set('trust proxy', true);
app.disable('x-powered-by');
app.post('/', function(req,res){
try
{
var body=JSON.parse(req.body.curl);
}
catch(err)
{
res.send({msg: 'invalid command', error: err});
}
if(body.method !=undefined && body.method == "POST")
{
let options = {
url:body.url,
method:body.method,
headers:body.headers,
body: JSON.stringify(body.body)
};
request(options, (error, response, body) => {
if (error) {
console.error("An error has occurred: ", error);
res.send(error);
}
else {
let responseData = JSON.parse(body);
res.send(responseData);
}
});
}
///Ends if
else if(body.method != undefined && body.method == "GET")
{
let options = {
// url: body.url+'?account='+body.body.params.account+'&limit='+body.body.params.limit+
// '&offset='+body.body.params.offset+'&&symbol='+body.body.params.symbol,
url: 'https://api.site.com/accounts/history'+body.symbol,
method: "GET",
headers: {"Content-type": "application/json"},
};
request(options, (error, response, body) => {
if (error) {
console.error("An error has occurred: ", error);
res.send(error);
}
else {
var withdraw = [], deposit = [];
body= JSON.parse(body);
body.forEach(el => {
if(el.from == "account"){
delete el.block;
delete el.symbol;
delete el.from_type;
delete el.to_type;
withdraw.push(el);
}
else{
delete el.block;
delete el.symbol;
delete el.from_type;
delete el.to_type;
deposit.push(el);
}
});
res.json([{"WITHDRAWS": withdraw},{"DEPOSITS":deposit}]);
}
});
}
//ends else if
else
{
const active_key = body.wif;
const key = dsteem.PrivateKey.fromString(active_key);
const account = "account";
const my_id= "mainnet";
const my_data= {"contractName":"tokens", "contractAction":"transfer","contractPayload":{"symbol": "omg",
"to": body.to,"quantity":body.quantity,"memo": body.memo }};
client.broadcast.json({
required_auths: [account],
required_posting_auths: [],
id: my_id,
json: JSON.stringify(my_data),
}, key).then(
result => {res.send(result)},
error => {res.send({msg: 'Something went wrong', error: error})}
)
}
//ends else
});
app.listen(port, function () {
console.log("Server listening on port: " + port);
});
body
(or ratherreq.body.curl
) to contain? - Chris GJSON.parse()
on that without first getting rid of the stuff that isn't JSON. - Chris G