If you’ve ever built a Flutter web app, you’ve probably run into one annoying issue: CORS errors during development.
Traditionally, fixing this meant:
- tweaking backend headers
- setting up a reverse proxy (like Nginx)
- or using messy workarounds
But Flutter recently introduced something that simplifies all of this:
A built-in web development proxy
And honestly, it’s one of those small features that makes a huge difference in day-to-day workflow.
What Is Flutter’s Web Dev Proxy?
Flutter now allows you to define a local proxy using a simple config file:
web_dev_config.yaml
This lets your Flutter web app forward API requests to your backend automatically, without worrying about CORS.
My Setup
Here’s the exact configuration I’m using:
server:
host: "0.0.0.0"
port: 8000
proxy:
- target: "<target_url>"
prefix: "/api/"
- target: "<target_url>"
prefix: "/files/"
How It Works
This setup means:
- Requests to
/api/...→ forwarded to your backend - Requests to
/files/...→ also forwarded to your backend
So in your Flutter code, you can simply write:
http.get(Uri.parse('/api/users'));
And Flutter will internally send it to:
<target_url>/api/users
No CORS issues. No extra setup.
Why This Is a Big Deal
1. No More CORS Configuration
You don’t need to:
- enable CORS on your backend
- install middleware
- debug browser errors
3. No External Proxy Needed
Previously, many developers used:
- Nginx
- webpack dev server proxies
- custom scripts
Now Flutter handles it natively.
Optional: HTTPS Support
If you want to test secure environments locally, you can enable HTTPS:
https:
cert-path: "/path/to/cert.pem"
cert-key-path: "/path/to/key.pem"
If you’re building Flutter web apps, this is definitely worth adding to your workflow.
Just create a web_dev_config.yaml, define your proxy rules, and run your app.
Top comments (0)