Cors worker with json post (CROSS DOMAIN)


#1

I’m new to workers and trying to find some boiler plate help so i can script a worker that:

  1. handles a cors (cross domain request)
  2. handles a post request
  3. reads the json body string
  4. adds a property to the the json
  5. forwards it to a new url on my server intact as a post request

Is this possible?


#2

Hi @martin1,

This boilerplate CORS script might help you get started: Handling preflight requests

That performs steps 1-3 in your list. Most of the modifications you’d need to make steps 4 and 5 work would be in the handlePost() function, though you may wish to remove the GET/HEAD pass-through behavior, too.

Harris