Attempting to incorporate Thrift API calls into my Angular application, I used the following command to generate client files:
thrift-0.18.1.exe -r --gen js:ts <myService.thrift>
The command successfully created both JavaScript (js) and TypeScript (ts) files which were then added into the app. Additionally, the thrift library was installed with pnpm add thrift
import * as thrift from 'thrift';
import { MyServiceClient } from './myService';
import { Injectable } from '@angular/core';
@Injectable()
export class TestMyClient {
constructor() {
const host = 'localhost';
const port = 45000;
const opts = { transport: thrift.TBufferedTransport, protocol: thrift.TJSONProtocol, headers: { 'Content-Type': 'application/vnd.apache.thrift.json', }, https: true, path: '/url/path', useCORS: true, };
const connection = thrift.createXHRConnection(host, port, opts);
const thriftClient = thrift.createXHRClient(MyServiceClient, connection);
connection.on('error', (err) => { console.error(err); });
const data = thriftClient.myAPI();
console.log(`data received: ${data}`);
}
}
However, upon running the code, an error is encountered:
Uncaught ReferenceError: myService_myAPI_args is not defined
This error seems to be originating from webpack during the bundling process of generated client files. Is there a step missing in the configuration? Any additional setup required?