Skip to content

Commit

Permalink
docs: Describe proxy setup
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Feb 5, 2021
1 parent 8291bfb commit 3d45369
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,48 @@ npx ts-node ./src/demo/dump-candles.ts

**Tip:** There is a [.env.defaults](https://github.com/bennycode/coinbase-pro-node/blob/main/.env.defaults) file which serves as a template. Just remove its `.defaults` extension and enter your credentials to get started. Do not commit this file (or your credentials) to any repository!

### Web Frontend Applications

The "coinbase-pro-node" library was built to be used in Node.js environments BUT you can also make use of it in web frontend applications (using React, Vue.js, etc.). However, due to the [CORS restrictions](https://developer.mozilla.org/docs/Web/HTTP/CORS) of modern web browser, you will have to use a proxy server.

A proxy server can be setup with webpack's [DevServer proxy configuration](https://webpack.js.org/configuration/dev-server/#devserverproxy) or [http-proxy-middleware](https://www.npmjs.com/package/http-proxy-middleware).

Here is an example:

**Backend**

```typescript
import {createProxyMiddleware} from 'http-proxy-middleware';
import express from 'express';

const app = express();

app.use(
'/api-coinbase-pro',
createProxyMiddleware({
target: 'https://api.pro.coinbase.com',
changeOrigin: true,
pathRewrite: {
[`^/api-coinbase-pro`]: '',
},
})
);
```

Later on, you can use the proxy URL (`/api-coinbase-pro` from above) in your web application to initialize "coinbase-pro-node" with it:

**Frontend**

```typescript
const client = new CoinbasePro({
httpUrl: '/api-coinbase-pro',
apiKey: '',
apiSecret: '',
passphrase: '',
useSandbox: false,
});
```

### Real-world examples

Checkout [GitHub's dependency graph][6] to see who uses "coinbase-pro-node" in production. There are also [npm packages][7] depending on "coinbase-pro-node".
Expand Down

0 comments on commit 3d45369

Please sign in to comment.