Commit 0ec77fbe authored by Tobias Steiner's avatar Tobias Steiner
Browse files

Change resolving of urls

parent 8764cb12
Pipeline #2999 passed with stage
in 2 minutes and 41 seconds
......@@ -152,7 +152,7 @@ export class ApiController {
* @param {e.Response} res
* @param {e.NextFunction} next
*/
public static queryKafka(req: InterfaceRequestKafka, res: Response, next: NextFunction) {
public static async queryKafka(req: InterfaceRequestKafka, res: Response, next: NextFunction) {
// prepared data from the middleware
const message = req.message;
const id = message.id;
......@@ -195,7 +195,7 @@ export class ApiController {
clearTimeout(unsubscribeTimer);
}
// wait for kafka to answer
kafkaEventEmitter.on(`data-${id}`, waitForResponse);
kafkaEventEmitter.on(`data-${id}`, await waitForResponse);
// a bit hackish but we need to unsubscribe from the event if no answer from kafka arrives
// todo: perhaps a different unsubscribeTimeout
......
......@@ -55,9 +55,17 @@ export class ResponseCollector {
if(this.config.indexOf(data.name) > -1){
// check if array
if(Array.isArray(data.data.links)) {
data.data.links = await data.data.links.map((d) => UrlResolver.getProvider(d, this.language));
} else {
data.data.links = await UrlResolver.getProvider(data.data.links, this.language);
data.data.links = await data.data.links.map(async (d) => {
const a = {};
try {
const provider = await UrlResolver.getProvider(d, this.language);
a[provider] = d;
return a;
} catch {
a['unknown'] = d;
return a;
}
});
}
if(Array.isArray(this.finalData.data[data.name])) {
......
......@@ -7,8 +7,7 @@ import {core} from '../app';
class UrlResolver {
static baseUrl = 'http://url-resolver/v1/urltoprovider/';
constructor() {
UrlResolver.baseUrl = core.getNconf().get('url-resolver');
console.log(UrlResolver.baseUrl);
UrlResolver.baseUrl = core.getNconf().get('url-resolver');
}
public static async getProvider(url: string, language: string = 'de') {
try {
......@@ -16,6 +15,7 @@ class UrlResolver {
return provider.data.name[language];
} catch(err) {
console.log(err);
return 'unknown';
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment