-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[3.38] add web-dev-config file description #12232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SydneyBao
wants to merge
12
commits into
flutter:main
Choose a base branch
from
SydneyBao:web-dev-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9d6f3b3
add web-dev-config-file
SydneyBao 04a5e7b
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 ba21820
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 c19a59a
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 398c1ba
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 aa92445
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 3bcc649
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 1986419
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 e00eedd
Update src/content/platform-integration/web/web-dev-config-file.md
sfshaza2 f895e25
add to index
SydneyBao 63615df
update index
SydneyBao 069b587
Minor formatting clean up
parlough File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
src/content/platform-integration/web/web-dev-config-file.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
--- | ||
title: Set up a web development configuration file | ||
description: Centralize web development settings including a development proxy | ||
short-title: Web development configuration | ||
--- | ||
|
||
# Set up a web development configuration file | ||
**By Sydney Bao** | ||
|
||
Flutter web includes a development server that defaults to serving your application in the `localhost` domain via HTTP on a randomly assigned port. While command-line arguments offer a quick way to modify the server’s behavior, this document focuses on a more structured approach: defining your server's behavior through a centralized `web_dev_config.yaml` file. This configuration file allows you to customize server settings---host, port, HTTPS settings, and proxy rules---ensuring a consistent development environment. | ||
|
||
## Create a configuration file | ||
|
||
Add a `web_dev_config.yaml` file in the root directory of your Flutter project. If you haven’t set up a Flutter project, visit [Building a web application with Flutter](https://docs.flutter.dev/platform-integration/web/building) to get started. | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Add configuration settings | ||
|
||
### Basic server configuration | ||
|
||
You can define the host, port, and HTTPS settings for your development server! | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```yaml | ||
#web_dev_config.yaml | ||
server: | ||
host: "0.0.0.0" # Defines the binding address <string> | ||
port: 8080 # Specifies the port <int> for the development server | ||
https: | ||
cert-path: "/path/to/cert.pem" # Path <string> to your TLS certificate | ||
cert-key-path: "/path/to/key.pem" # Path <string> to TLS certificate key | ||
``` | ||
|
||
### Custom headers | ||
|
||
You can also inject custom HTTP headers into the development server’s responses! | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```yaml | ||
#web_dev_config.yaml | ||
server: | ||
headers: | ||
- name: "X-Custom-Header" # Name <string> of the HTTP header | ||
value: "MyValue" # Value <string> of the HTTP header | ||
- name: "Cache-Control" | ||
value: "no-cache, no-store, must-revalidate" | ||
``` | ||
|
||
### Proxy configuration | ||
|
||
Requests are matched in order from the `web_dev_config.yaml` file. | ||
|
||
#### Basic string proxy | ||
|
||
Use the `prefix` field for simple path prefix matching! | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```yaml | ||
#web_dev_config.yaml | ||
server: | ||
proxy: | ||
- target: "http://localhost:5000/" # Base URL <string> of your backend | ||
prefix: "/users/" # Path <string> | ||
- target: "http://localhost:3000/" | ||
prefix: "/data/" | ||
replace: "/report/" # Replacement <string> of path in redirected URL (optional) | ||
- target: "http://localhost:4000/" | ||
prefix: "/products/" | ||
replace: "" | ||
``` | ||
|
||
**Explanation:** | ||
|
||
* A request to `/users/names` will be forwarded to `http://localhost:5000/users/names`. | ||
* A request to `/data/2023/` will be forwarded to `http://localhost:4000/report/2023` because `replace: “/report/”` replaces the `/data/` prefix | ||
* A request to `/products/item/123` will be forwarded to `http://localhost:4000/item/123`. `replace: ""` removes the `/products/` prefix by replacing it with an empty string | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Advanced regex proxy | ||
|
||
You can also use the `regex` field for more flexible and complex matching! | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```yaml | ||
#web_dev_config.yaml | ||
server: | ||
proxy: | ||
- target: "http://localhost:5000/" | ||
regex: "/users/(\d+)/$" # Path <string> matches requests like /users/123/ | ||
- target: "http://localhost:4000/" | ||
regex: "^/api/(v\d+)/(.*)" # Matches requests like /api/v1/users | ||
replace: "/$2?apiVersion=$1" # Allows capture groups (optional) | ||
``` | ||
|
||
**Explanation:** | ||
|
||
* A request to `/users/123/` matches the first rule exactly, so it will be forwarded to `http://localhost:5000/users/123/` | ||
* A request to `/api/v1/users/profile/` starts with the second rule path, so it will be forwarded to `http://localhost:4000/users/profile/?apiVersion=v1` | ||
sfshaza2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Configuration precedence | ||
|
||
Remember the order of precedence for settings: | ||
|
||
1. **Command-line arguments** (such as `--web-hostname`, `--web-port`) | ||
2. **`web_dev_config.yaml` settings** | ||
3. **Built-in default values** |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.