Cloudflare workers
Opened this issue · 1 comments
Is this library compatible with cloudflare workers?
Thanks for your question, @stefanofa! Currently, is-odd-ai isn't compatible with Cloudflare Workers, but we'd welcome a contribution to add support. Here's a breakdown of the current incompatibilities and a roadmap for adding Cloudflare Workers support while maintaining compatibility with existing environments:
Current incompatibilities:
- Environment variables: We use
dotenv
, not supported in Cloudflare Workers. - Node.js dependencies: We use
axios
, unavailable in the Cloudflare Workers runtime. - Module system: Cloudflare Workers use ES modules, while we currently use CommonJS.
Roadmap for Cloudflare Workers compatibility:
- Implement environment detection for appropriate method selection
- Replace
dotenv
with a solution that works in both Node.js and Cloudflare Workers - Switch from
axios
to an isomorphic fetch solution - Convert the package to use ES modules (with CommonJS fallback for backward compatibility)
- Create a Cloudflare Worker-specific entry point
- Update the OpenAI API call to work within Cloudflare Workers' constraints
- Add Cloudflare Workers setup instructions to the README
- Create example code for using is-odd-ai in a Cloudflare Worker
- Update the test suite to cover both Cloudflare Workers and Node.js environments
Key considerations:
- Ensure the package continues to work in non-Cloudflare Worker environments
- Maintain backward compatibility with existing Node.js usage
- Thoroughly test in both Cloudflare Workers and Node.js environments
If you're up for tackling this, feel free to submit a pull request with your implementation. We're excited to see how you approach adding Cloudflare Workers support while maintaining compatibility with our existing environments!
Let us know if you have any questions or need any clarifications as you work on this feature. Good luck, and thanks for considering contributing to is-odd-ai! 🚀