Announcing wrangler dev — the Edge on localhost
Cloudflare Workers — our serverless platform — allows developers around the world to run their applications from our network of 200 datacenters, as close as possible to their users.
A few weeks ago we announced a release candidate for
wrangler dev — today, we’re excited to take
wrangler dev, the world’s first edge-based development environment, to GA with the release of wrangler 1.11.
Think locally, develop globally
It was once assumed that to successfully run an application on the web, one had to go and acquire a server, set it up (in a data center that hopefully you had access to), and then maintain it on an ongoing basis. Luckily for most of us, that assumption was challenged with the emergence of the cloud. The cloud was always assumed to be centralized — large data centers in a single region (“us-east-1”), reserved for compute. The edge? That was for caching static content.
Again, assumptions are being challenged.
Cloudflare Workers is about moving compute from a centralized location to the edge. And it makes sense: if users are distributed all over the globe, why should all of them be routed to us-east-1, on the opposite side of the world, causing latency and degrading user experience?
But challenging one assumption caused others to come into view. One of the most obvious ones was: would a local development environment actually provide the best experience for someone looking to test their Worker code? Trying to fit the entire Cloudflare edge, with all its dependencies onto a developer’s machine didn’t seem to be the best approach. Especially given that the place the developer was going to run that code in production was mere milliseconds away from the computer they were running on.
When I was in college, getting started with programming, one of the biggest barriers to entry was installing all the dependencies required to run a single library. I would go as far as to say that the third, and often forgotten hardest problem in computer science is dependency management.
We’re not the first to try and unify development environments across machines — tools such as Docker aim to solve this exact problem by providing a prepackaged development environment.
Yet, packaging up the Workers runtime is not quite so simple.
Beyond the Workers runtime, there are many components that make up Cloudflare’s edge, including DNS resolution, the Cloudflare cache — all of those parts are what makes Cloudflare Workers so powerful. That means that without those components, a standalone runtime is insufficient to represent the behavior of Worker request handling. The reason to develop locally first is to have the opportunity to experiment without affecting production. Thus, having a local development environment that truly reflects production is a requirement.
wrangler dev provides all the convenience of a local development environment, without the headache of trying to reproduce the reality of production locally — and then having to keep the two environments in sync.
By running at the edge, it provides a high fidelity, consistent experience for all developers, without sacrificing the speedy feedback loop of a local development environment.
As you update your code,
wrangler dev will detect changes, and push the new version of your code to the edge.
console.log() at your fingertips
Previously to extract your console logs from the Workers runtime, you had to have the Workers Preview open in a browser window at all times. With
wrangler dev, you can receive your own logs, directly to your terminal of choice.
Cache API, KV, and more!
wrangler dev runs on the edge, you can now easily test the state of a cache.put(), without having to deploy your Worker to production.
wrangler dev will spin up a new KV namespace for development, so you don’t have to worry about affecting your production data.
And if you’re looking to test out some of the features provided on
request.cf that provide rich information about the request such as geo-location — they will all be provided from the Cloudflare data center.
wrangler dev is now available in the latest version of Wrangler, the official Cloudflare Workers CLI.
To get started, follow our installation instructions here.
wrangler dev is just our first foray into giving our developers more visibility and agility with their development process.
We recognize that we have a lot more work to do to meet our developers needs, including providing an easy testing framework for Workers, and allowing our customers to observe their Workers’ behavior in production.
wrangler dev provides a quick feedback loop between our developers and their code, we love to have a tight feedback loop between our developers and our product. We love to hear what you’re building, how you’re building it, and how we can help you build it better.
via The Cloudflare Blog https://meson.in/2DaAAwa
August 26, 2020 at 08:04PM