diff --git a/src/bin/www.js b/src/bin/www.js index a9ef672..17ad166 100644 --- a/src/bin/www.js +++ b/src/bin/www.js @@ -1,8 +1,6 @@ import express from "express"; import colors from "colors"; -import axios from "axios"; -import util from "util"; -// import soap from "soap"; +import * as soap from "soap"; // colors colors.enable(); @@ -15,36 +13,25 @@ app.listen(port, () => { 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 const routes = express.Router(); app.use("/", routes); // routes controller routes.route("").get((request, response) => { - axios - .post(url, xml, headers) - .then((response) => { - console.log(`${util.inspect(response.data, false, null)}`.yellow); + 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); + }); + }); }) - .catch((error) => { - console.log(error); + .then((result) => { + console.log(`CDI (${args.data}) : ${result.getValorReturn["$value"]}`.yellow); + response.json(parseFloat(result.getValorReturn["$value"])); }); - response.send("done"); });