I’ve been experimenting with various new age deployment and JAMStack solutions out there.
Since I’ve been using cloudflare for over 8 years (as of writing this post), I thought I’ll give it a shot as a cheap
caching server replacing Redis + Node.js. Writing the REST server to handle requests using Cloudflare Workers
and KV is fairly straightforward:
And as expected, httpie was able to perfectly POST and GET the data. But as soon as I shot up the devconsole to
make a request, I was faced with the dreaded CORS error. Usually solving CORS is fairly straightforward, but this
error was unique as the request wasn’t really throwing any CORS error, it was just returning an empty
response.
The way to solve this problem is twofold:
Add a handler for OPTIONS.
Return Access-Control-Allow-Origin, on all requests.
Don’t think I was able to find a solution on the internet, but knowing how CORS is handled helped.