Proxy gRPC-Web directly in your Go Server (without envoy)

Roger Chapman
2 min readintermediate
--
View Original

Overview

The article discusses how to proxy gRPC-Web directly in a Go server without using Envoy, focusing on a simple setup for development. It highlights the use of the gRPC-Web implementation and introduces a custom tool for better visibility of gRPC-Web requests.

What You'll Learn

1

How to set up a gRPC server in Go without Envoy

2

Why using h2c for HTTP/2 over cleartext is beneficial during development

3

How to use gRPC-Web Dev Tools for inspecting gRPC-Web requests

Key Questions Answered

How can I proxy gRPC-Web in a Go server without Envoy?
You can proxy gRPC-Web in a Go server by using the grpc-web package and configuring the gRPC server to handle HTTP/2 requests. The setup involves wrapping the gRPC server with grpcweb.WrapServer and using h2c for cleartext HTTP/2. This allows you to run a single binary without needing Envoy.
What is the purpose of the gRPC-Web Dev Tools?
The gRPC-Web Dev Tools is a Chrome extension that allows developers to view gRPC-Web requests and responses in a more readable JSON format instead of base64 strings. This tool enhances the debugging experience for frontend engineers working with gRPC-Web.
Why is using h2c not recommended for production?
Using h2c allows HTTP/2 over cleartext, which is convenient for development as it eliminates the need for TLS certificates. However, this approach is not recommended for production environments due to security vulnerabilities associated with unencrypted traffic.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Backend
Grpc
Used to implement the server-side functionality for handling gRPC-Web requests.
Frontend
Grpc-web
Enables web clients to communicate with gRPC services.
Tools
Chrome
Used in conjunction with gRPC-Web Dev Tools for inspecting network requests.
Backend
Golang.org/X/Net/Http2/H2c
Allows HTTP/2 over cleartext for development purposes.

Key Actionable Insights

1
Implementing a gRPC server without Envoy simplifies the development process by reducing dependencies.
This approach allows engineers to run a single binary, making it easier to set up and manage during development phases.
2
Using gRPC-Web Dev Tools can significantly enhance your debugging capabilities.
By converting gRPC-Web requests into JSON format, frontend engineers can more easily analyze and troubleshoot network traffic.
3
Understanding the limitations of using h2c is crucial for maintaining security.
While h2c is useful for development, transitioning to a secure setup with TLS is essential before moving to production to protect sensitive data.

Common Pitfalls

1
Relying on h2c for production environments can expose your application to security risks.
While h2c simplifies development, it is important to implement TLS in production to ensure data security and compliance with best practices.