Browse Source

update

master
yutsuo 6 years ago
parent
commit
bccf54412e
  1. 41
      src/bin/www.js

41
src/bin/www.js

@ -1,8 +1,6 @@
import express from "express"; import express from "express";
import colors from "colors"; import colors from "colors";
import axios from "axios"; import * as soap from "soap";
import util from "util";
// import soap from "soap";
// colors // colors
colors.enable(); colors.enable();
@ -15,36 +13,25 @@ app.listen(port, () => {
console.log(`Express app running on Port: ${port}`.green); console.log(`Express app running on Port: ${port}`.green);
}); });
//soap example
const soap = require("soap");
const url = "https://www3.bcb.gov.br/wssgs/services/FachadaWSSGS?wsdl";
const args = { codigoSerie: "4392", data: "18/06/2020" };
soap
.createClientAsync(url)
.then((client) => {
return new Promise((resolve, reject) => {
client.getValor(args, (error, result) => {
error ? reject() : resolve(result);
});
});
})
.then((result) => {
console.log(result);
});
// express routes // express routes
const routes = express.Router(); const routes = express.Router();
app.use("/", routes); app.use("/", routes);
// routes controller // routes controller
routes.route("").get((request, response) => { routes.route("").get((request, response) => {
axios const url = "https://www3.bcb.gov.br/wssgs/services/FachadaWSSGS?wsdl";
.post(url, xml, headers) const args = { codigoSerie: 4392, data: "18/06/2020" };
.then((response) => { soap
console.log(`${util.inspect(response.data, false, null)}`.yellow); .createClientAsync(url)
.then((client) => {
return new Promise((resolve, reject) => {
client.getValor(args, (error, result) => {
error ? reject() : resolve(result);
});
});
}) })
.catch((error) => { .then((result) => {
console.log(error); console.log(`CDI (${args.data}) : ${result.getValorReturn["$value"]}`.yellow);
response.json(parseFloat(result.getValorReturn["$value"]));
}); });
response.send("done");
}); });

Loading…
Cancel
Save