Hi @martin1,
This boilerplate CORS script might help you get started: Handling preflight requests - #5 by webchad
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