Skip to content Skip to sidebar Skip to footer

How To Fix Coinbase Pro Api Request Headers?

I am trying to code to execute orders using Coinbase Pro API according to the Documentation provided. However, I got an error like this. Access to XMLHttpRequest at 'https://api.p

Solution 1:

Their API does support CORS, however it is misconfigured and does not permit the security headers that they require you to use! You can work around this by running an express proxy with middleware to re-write the headers:

import express from 'express'
import { createProxyMiddleware } from 'http-proxy-middleware'

const app = express()

app.use(express.static('client'))

const apiProxy = createProxyMiddleware({
  target: 'https://api.pro.coinbase.com',
  changeOrigin: true,
  onProxyRes: res => {
    res.headers = {
      ...res.headers,
      'access-control-allow-headers':
        'Content-Type, cb-access-key, cb-access-sign, cb-access-timestamp, cb-access-passphrase',
    }
  },
})

app.use('/', apiProxy)

app.listen(3001)

Post a Comment for "How To Fix Coinbase Pro Api Request Headers?"