grpc config_error ai_generated true

INTERNAL: grpc-web: CORS preflight failed for origin http://localhost:3000

ID: grpc/grpc-web-cors-failure

Also available as: JSON · Markdown · 中文
90%Fix Rate
88%Confidence
1Evidence
2024-03-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Envoy 1.26.0 active
gRPC-Web 1.48.0 active

Root Cause

The gRPC-Web proxy or server did not respond with the correct CORS headers for the preflight OPTIONS request.

generic

中文

gRPC-Web 代理或服务器未对预检 OPTIONS 请求返回正确的 CORS 头。

Official Documentation

https://github.com/grpc/grpc-web/blob/master/doc/cors.md

Workarounds

  1. 90% success Configure the gRPC-Web proxy (e.g., Envoy) to add CORS headers. Example Envoy config snippet: `cors: { allow_origin_string_match: [{ prefix: "http://localhost:3000" }], allow_methods: "POST, OPTIONS", allow_headers: "content-type,x-grpc-web", max_age: "86400" }`
    Configure the gRPC-Web proxy (e.g., Envoy) to add CORS headers. Example Envoy config snippet: `cors: { allow_origin_string_match: [{ prefix: "http://localhost:3000" }], allow_methods: "POST, OPTIONS", allow_headers: "content-type,x-grpc-web", max_age: "86400" }`
  2. 85% success If using a custom server, handle OPTIONS requests manually by returning 200 with appropriate CORS headers.
    If using a custom server, handle OPTIONS requests manually by returning 200 with appropriate CORS headers.

中文步骤

  1. Configure the gRPC-Web proxy (e.g., Envoy) to add CORS headers. Example Envoy config snippet: `cors: { allow_origin_string_match: [{ prefix: "http://localhost:3000" }], allow_methods: "POST, OPTIONS", allow_headers: "content-type,x-grpc-web", max_age: "86400" }`
  2. If using a custom server, handle OPTIONS requests manually by returning 200 with appropriate CORS headers.

Dead Ends

Common approaches that don't work:

  1. 100% fail

    Browsers enforce CORS; it cannot be disabled client-side.

  2. 60% fail

    The preflight request (OPTIONS) must be handled explicitly, not just the POST.

  3. 50% fail

    This only works for non-browser environments; the error is specific to browser-based gRPC-Web.