Skip to content

mier85/grpc-web-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grpc-web + golang

https://github.com/grpc/grpc-web

let's create our demo

prerequisites

steps

  • create a new project

      go mod init github.com/mier85/grpc-web-example
    
  • create a protobuf contract

      mkdir contract
      touch contract/contract.proto
    
  • now let's create the corresponding sources:

      # use protoc, generate go files including the grpc stub and make the path relative to where it should be
      protoc --go_out=plugins=grpc,paths=source_relative:. contract/contract.proto        
    
  • now let's build the service. first we need to get some dependencies

     # in this step we download half of the internet
     go get -u google.golang.org/grpc
     
     # we don't need this, but it'll give us some nice extras
     go get -u github.com/grpc-ecosystem/go-grpc-middleware
     
     # get some logs going for us
     go get -u go.uber.org/zap
    
  • now let's create the web stuff

    # create the folders that we will need
    mkdir -p js/src/contract
    
    # similar to what we did with the go source, let's create the js sources now 
    protoc -I=./contract contract/contract.proto --js_out=import_style=commonjs:js/src/contract --grpc-web_out=import_style=commonjs,mode=grpcweb:js/src/contract
    
    cd js
    
    # now let's get to the hacky part, use webpack to create js that we can load inside the server
    npm init -y
    npm install --save-dev npx google-protobuf grpc-web webpack webpack-cli
    
    # create our client
    npx webpack --mode=development --output-library="grpcwebexample"  
    
  • let's get it running

      # last but not least, we need to proxy the web-request to the web endpoint 
      docker build -f Dockerfile.envoy -t grpcwebexample/envoy .
      docker run --net=host grpcwebexample/envoy
    

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published