Cloudflare
Cloudflare’s Workers service provides a serverless JavaScript runtime environment.
By deploying code at the edge of the user’s network, Cloudflare Workers allow requests to be executed directly at the nearest node, significantly improving access speed and response efficiency.
Getting Started
When creating an application, choose cloudflare
as the runtime environment.
Runtime
Your code will run within the Cloudflare Workers runtime, which does not use Bun or Node.js as runtimes. Therefore, when writing code in the Cloudflare Workers environment, you need to rely on the features available in vanilla JavaScript and avoid using features that depend on unsupported Node.js or Bun functionalities.
Microservices
Cloudflare Workers ultimately bundle your code into a single JavaScript file and upload it, which improves performance but also eliminates Milkio’s ability to load on demand because all of your application’s code is loaded into memory at the outset.
Therefore, to maintain high performance in Cloudflare Workers when you have a large number of APIs, you should not pack too many APIs into one Worker. You can create multiple Milkio applications and deploy them to different Workers, communicating between them using your client package.
Testing
Cloudflare Workers use Wrangler as a tool for development and deployment. However, Wrangler currently does not support the ability to directly execute a JavaScript file in its own environment. Therefore, when testing with Milkio, the tests are actually executed by Bun.
To ensure that tests accurately reflect the actual performance in the Cloudflare Workers environment, we recommend using test.client
for testing. This way, the tests will send requests to Cloudflare Workers instead of executing the code you want to test in Bun.
Deployment
Modify your /wrangler.toml
, changing the name
to your Workers’ name.
Run bun run deploy
to deploy your application to Cloudflare Workers. If it’s your first time running this command, you may need to log in.