Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f0ad433

Browse files
📝 Update includes in docs/en/docs/advanced/behind-a-proxy.md (#12583)
1 parent 5b1963d commit f0ad433

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

docs/en/docs/advanced/behind-a-proxy.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ In this case, the original path `/app` would actually be served at `/api/v1/app`
1818

1919
Even though all your code is written assuming there's just `/app`.
2020

21-
```Python hl_lines="6"
22-
{!../../docs_src/behind_a_proxy/tutorial001.py!}
23-
```
21+
{* ../../docs_src/behind_a_proxy/tutorial001.py hl[6] *}
2422

2523
And the proxy would be **"stripping"** the **path prefix** on the fly before transmitting the request to the app server (probably Uvicorn via FastAPI CLI), keeping your application convinced that it is being served at `/app`, so that you don't have to update all your code to include the prefix `/api/v1`.
2624

@@ -98,9 +96,7 @@ You can get the current `root_path` used by your application for each request, i
9896

9997
Here we are including it in the message just for demonstration purposes.
10098

101-
```Python hl_lines="8"
102-
{!../../docs_src/behind_a_proxy/tutorial001.py!}
103-
```
99+
{* ../../docs_src/behind_a_proxy/tutorial001.py hl[8] *}
104100

105101
Then, if you start Uvicorn with:
106102

@@ -127,9 +123,7 @@ The response would be something like:
127123

128124
Alternatively, if you don't have a way to provide a command line option like `--root-path` or equivalent, you can set the `root_path` parameter when creating your FastAPI app:
129125

130-
```Python hl_lines="3"
131-
{!../../docs_src/behind_a_proxy/tutorial002.py!}
132-
```
126+
{* ../../docs_src/behind_a_proxy/tutorial002.py hl[3] *}
133127

134128
Passing the `root_path` to `FastAPI` would be the equivalent of passing the `--root-path` command line option to Uvicorn or Hypercorn.
135129

@@ -309,9 +303,7 @@ If you pass a custom list of `servers` and there's a `root_path` (because your A
309303

310304
For example:
311305

312-
```Python hl_lines="4-7"
313-
{!../../docs_src/behind_a_proxy/tutorial003.py!}
314-
```
306+
{* ../../docs_src/behind_a_proxy/tutorial003.py hl[4:7] *}
315307

316308
Will generate an OpenAPI schema like:
317309

@@ -358,9 +350,7 @@ The docs UI will interact with the server that you select.
358350

359351
If you don't want **FastAPI** to include an automatic server using the `root_path`, you can use the parameter `root_path_in_servers=False`:
360352

361-
```Python hl_lines="9"
362-
{!../../docs_src/behind_a_proxy/tutorial004.py!}
363-
```
353+
{* ../../docs_src/behind_a_proxy/tutorial004.py hl[9] *}
364354

365355
and then it won't include it in the OpenAPI schema.
366356

0 commit comments

Comments
 (0)