app.post('/', (req, res) => {
const x = translate(req.body.query, req.body.to);
console.log(x); // vypise Promise { <pending> }
res.json(x); // v postman pride prazdny objekt {}
})
server.js vracia teraz prazdny objekt
tu funkciu v translator.js mam takto:
const translate = async (string, langCode) => {
try {
const x = await axios({
method: "POST",
url: process.env.API_URL,
headers: {
"content-type": "application/json",
"x-rapidapi-host": process.env.API_HOST,
"x-rapidapi-key": process.env.API_KEY,
"accept": "application/json",
"useQueryString": true
},
params: {
"profanityAction": "NoAction",
"textType": "plain",
"to": `${langCode}`,
"api-version": "3.0"
},
data: [{
"Text": `${string}`
}]
});
return x;
} catch (err) {
console.error(err);
}
}