Using Ory with Cloudflare workers
Blog post from Ory
During a Christmas break exploration of serverless and infrastructure advancements, the author delved into Cloudflare Workers, Ory.sh, and PlanetScale, encountering a notable issue with Cloudflare Workers' library support due to its V8 engine, which does not support some Node.js NPM modules like Axios. This limitation affected libraries such as @ory/client that rely on Axios, leading to errors when attempting to run them on Cloudflare Workers. To resolve the issue, the author implemented a solution using the @haverstack/axios-fetch-adapter, which allows Axios to utilize Fetch APIs instead of its default Node-dependent adapter. This approach involved modifying the Ory API configuration to include the adapter, enabling Axios-based modules to function correctly within Cloudflare Workers. The author shares detailed implementation steps, including middleware setup with itty-router, to authenticate Ory sessions via cookies and ensure the proper operation of Axios-based requests in this serverless environment.