You skipped over the relevant part and went to background functions. The relevant part was this:
In your code, you’ve done that for a 200, but browsers send a preflight request with the OPTIONS method. Since in your code, you’re filtering for the POST method, the response you’re sending for POST doesn’t include those headers causing an issue.
You simply need to add those headers for the HTTP 405 as well.