Construct Lingva URL using url-join
| @@ -4,6 +4,7 @@ import fetch from 'node-fetch'; | |||
| 4 | import express from 'express'; | 4 | import express from 'express'; |
| 5 | import { translate as bingTranslate } from 'bing-translate-api'; | 5 | import { translate as bingTranslate } from 'bing-translate-api'; |
| 6 | import iconv from 'iconv-lite'; | 6 | import iconv from 'iconv-lite'; |
| 7 | import urlJoin from 'url-join'; | ||
| 7 | 8 | ||
| 8 | import { readSecret, SECRET_KEYS } from './secrets.js'; | 9 | import { readSecret, SECRET_KEYS } from './secrets.js'; |
| 9 | import { getConfigValue, uuidv4 } from '../util.js'; | 10 | import { getConfigValue, uuidv4 } from '../util.js'; |
| @@ -220,7 +221,7 @@ router.post('/lingva', jsonParser, async (request, response) => { | |||
| 220 | console.log('Input text: ' + text); | 221 | console.log('Input text: ' + text); |
| 221 | 222 | ||
| 222 | try { | 223 | try { |
| 223 | const url = `${baseUrl}/auto/${lang}/${encodeURIComponent(text)}`; | 224 | const url = urlJoin(baseUrl, 'auto', lang, encodeURIComponent(text)); |
| 224 | const result = await fetch(url); | 225 | const result = await fetch(url); |
| 225 | 226 | ||
| 226 | if (!result.ok) { | 227 | if (!result.ok) { |