CORS proxy with 3rd party API

I’m using the CORS proxy example here trying to proxy an 3rd party api request with the worker. I’ve tested with Postman and the request completes and returns JSON from the api. However when performing the api request from a Vue application using axios on the frontend it seems the request is not received by the api and JSON is not returned, although all the correct headers are there in the response.

Anyone have an idea if I have an issue with how the worker is handling the request? Below is the worker function handling proxying the api request:

async function handleRequest(request) {
  const url = new URL(request.url)
  const apiUrl = url.searchParams.get('apiurl')

  // Rewrite request to point to API url. This also makes the request mutable
  // so we can add the correct Origin header to make the API server think
  // that this request isn't cross-site.
  request = new Request(apiUrl, request)
  request.headers.set('Origin', new URL(apiUrl).origin)
  let response = await fetch(apiUrl, request)

  // Recreate the response so we can modify the headers
  response = new Response(response.body, response)

  // Set CORS headers
  response.headers.set('Access-Control-Allow-Origin', url.origin)

  // Append to/Add Vary header so browser will cache response correctly
  response.headers.append('Vary', 'Origin')

  return response

And this is the axios request made to the worker:

const response = await this.$
            new URLSearchParams(params)

Any ideas/thoughts are greatly appreciated!

Browsers always make an OPTIONS request first, to check if CORS is allowed.
You need to account for that, see more here.