You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
import express from "express"; |
|
import colors from "colors"; |
|
import axios from "axios"; |
|
import util from "util" |
|
|
|
// colors |
|
colors.enable(); |
|
|
|
// express app |
|
const app = express(); |
|
const port = process.env.NODEJS_PORT || 3001; |
|
|
|
app.listen(port, () => { |
|
console.log(`Express app running on Port: ${port}`.green); |
|
}); |
|
|
|
// data |
|
const url = "https://www3.bcb.gov.br/wssgs/services/FachadaWSSGS?method=getValor"; |
|
const headers = { |
|
headers: { |
|
"user-agent": "AIR-nodejs", |
|
"Content-Type": "text/xml;charset=UTF-8", |
|
soapAction: "https://www3.bcb.gov.br/wssgs/services/FachadaWSSGS/getValor", |
|
}, |
|
}; |
|
const xml = `\ |
|
<?xml version="1.0" encoding="utf-8"?> |
|
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
|
<soapenv:Body> |
|
<getValor xmlns="https://www3.bcb.gov.br/wssgs/services/FachadaWSSGS"> |
|
<codigoSerie>4392</codigoSerie> |
|
<data>18/06/2020</data> |
|
</getValor> |
|
</soapenv:Body> |
|
</soapenv:Envelope> |
|
`; |
|
|
|
// 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); |
|
}) |
|
.catch((error) => { |
|
console.log(error); |
|
}); |
|
response.send("done"); |
|
});
|
|
|