Skip to content

Commit

Permalink
Merge 0f7f424 into 1b84e6c
Browse files Browse the repository at this point in the history
  • Loading branch information
winguse committed Apr 2, 2018
2 parents 1b84e6c + 0f7f424 commit 2fdbe1c
Show file tree
Hide file tree
Showing 7 changed files with 1,501 additions and 282 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ envoyFetch(params, url, init /* init like original node-fetch */)
const yourOldRequestParams = {}; /* url or options */
request(envoyRequestParamsRefiner(yourOldRequestParams, context /* or headers, grpc.Metadata */ ))

// for gRPC
// for gRP
const client = new Ping((
`${context.envoyEgressAddr}:${context.envoyEgressPort}`, // envoy egress port
grpc.credentials.createInsecure()
Expand All @@ -256,6 +256,27 @@ client.pathToRpc(
Check out the [detail document](https://tubitv.github.io/envoy-node/) if needed.
## Context store
Are you finding it's too painful for you to propagate the context information through function calls' parameter?
If you are using Node.js V8, here is a solution for you:
```javascript
import { envoyContextStore } from "envoy-node"; // import the store

envoyContextStore.enable(); // put this code when you application init

// for each request, call this:
envoyContextStore.set(new EnvoyContext(req.headers));

// for later get the request, simply:
envoyContextStore.get();
```
**IMPORTANT**: according to the implementation, it's strictly requiring the `set` method is called exactly once per request. Or you will get incorrect context. Please check the document for more details. (TBD: We are working on a blog post for the details.)
## For dev and test, or migrating to Envoy
If you are developing the application, you may probably do not have Envoy running. You may want to call the service directly:
Expand All @@ -280,13 +301,13 @@ new EnvoyContext({
* If this field is set to `undefined`, this library will also try to read it from `x-tubi-envoy-managed-host`.
* You can set in envoy config, like this:
*
* ```yaml
* ``yaml
* request_headers_to_add:
* - key: x-tubi-envoy-managed-host
* value: hostname:12345
* - key: x-tubi-envoy-managed-host
* value: foo.bar:8080
* ```
* ``
*
* If you set this to be an empty set, then no traffic will be route to envoy.
*/
Expand Down

0 comments on commit 2fdbe1c

Please sign in to comment.