grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.65k stars 764 forks source link

cant get client working with mode=grpcweb #1051

Closed danielblignaut closed 3 years ago

danielblignaut commented 3 years ago

Hi,

When I run my configuration set with:

the generated client stub doesn't seem to execute properly. I am using typescript and tried with import_style=typescript to no success either.

When I use

and I import the actualy typescript client that uses promises, my requests work as expected

code below:


import xmlhttprequest from 'xmlhttprequest'
global.XMLHttpRequest = xmlhttprequest.XMLHttpRequest

import * as grpc from '@grpc/grpc-js'
import { ReadToDoByIdRequest } from './__generated__/grpc/nodejs/com/todo/v1/todo_pb'
import { ApplicationServiceClient }  from './__generated__/grpc/nodejs/application/v1/service_grpc_web_pb'

(async function() { 

    const SERVER_HTTP_ADDRESS = '***'

    const client = new ApplicationServiceClient(SERVER_HTTP_ADDRESS)

    const req = new ReadToDoByIdRequest()
    req.setId(1)

    await new Promise<void>((resolve, reject)=> {
        client.readToDoById(req, {}, function(err,res) {
            if(err) {
                return reject(err)
            }

            return resolve(res)
        })
    })

})()
    .catch((er)=> {
        console.error(er)
    })
    .finally(()=> {
        console.log('FINISHED')
    })

to run: npx ts-node ./index.ts

stanley-cheung commented 3 years ago

Sorry I won't be able to debug your specific problem, but our CI testing has been testing a basic TypeScript example with no problem. Here's a starting point: https://github.com/grpc/grpc-web/blob/master/net/grpc/gateway/docker/ts_client/Dockerfile

For me, doing this works:

$ docker-compose build node-server envoy ts-client
$ docker-compose up node-server envoy ts-client

And then hit localhost:8081/echotest.html.