如何在 Angular+Electron 应用程序中配置 Thrift

问题描述 投票:0回答:0

我正在尝试在我的 Angular 应用程序中调用 Thrift api。我使用以下方法生成了客户端文件:

thrift-0.18.1.exe -r --gen js:ts <myService.thrift>

它生成了 js 和 ts 文件,我将它们复制到我的应用程序中。使用

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}`);
    }
}

但是我得到这个错误:

Uncaught ReferenceError: myService_myAPI_args is not defined

好像是webpack在打包生成的客户端文件时抛出的。我在这里错过了什么吗?我需要添加更多配置吗?

angular typescript electron thrift thrift-protocol
© www.soinside.com 2019 - 2024. All rights reserved.