# How to do the best practice with FastAPI

**URL:** <https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334>\
**Category:** Panel\
**Tags:** panel, fastapi\
**Created:** [May 11, 2023, 2:09pm UTC](https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334 "2023-05-11T14:09:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xareelee](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/xareelee/32/4894_2.png) [@xareelee](https://discourse.holoviz.org/u/xareelee)\
**Post date:** [May 11, 2023, 2:09pm UTC](https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334/1 "2023-05-11T14:09:43Z")

</div>

Hi, I’ve been following the [Panel tutorial for FastAPI](https://panel.holoviz.org/user_guide/FastAPI.html).

I found that the embedded HTML contains the Panel/Bokeh server info which I do not intend to expose.

## Code (main.py)

Exactly the same code as the tutorial (providing `/` and `/app2` to show panels):

```python
# Following the Panel tutorial for Multiple apps
@app.get("/")
async def bkapp_page(request: Request):
    script = server_document('http://127.0.0.1:5000/app')
    return templates.TemplateResponse("base.html", {"request": request, "script": script})

@app.get("/app2")
async def bkapp_page2(request: Request):
    script = server_document('http://127.0.0.1:5000/app2')
    return templates.TemplateResponse("app2.html", {"request": request, "script": script})

```

## Visit FastAPI server (`127.0.0.1:8000`)

I open `127.0.0.1:8000` (FastAPI server) in my browser, and the HTML shows the bokeh server in the JS script (which is `127.0.0.1:8000`):

 ![Screenshot 2023-05-11 at 21.37.50](https://discourse.holoviz.org/uploads/default/original/2X/a/aa90320a968e4229a79b989ddfe8714bab1f05a1.png)

and so does `127.0.0.1:8000/app2`:

```auto
Here is a image you need to imagine, because I encounter "Sorry, new users can only put one embedded media item in a post", and it does not allow a new member to post with images.

https://discuss.python.org/t/discourse-message-sorry-new-users-can-only-put-one-embedded-media-item-in-a-post/8037/1

```

## Visit Bokeh server (`127.0.0.1:5000`)

Now I tried to visit `127.0.0.1:5000`, and it shows the Panel homepage which I did not intend to expose:

```auto
Here is a image you need to imagine, because I encounter "Sorry, new users can only put one embedded media item in a post", and it does not allow a new member to post with images.

https://discuss.python.org/t/discourse-message-sorry-new-users-can-only-put-one-embedded-media-item-in-a-post/8037/1

```

I try to go `App` page (`127.0.0.1:5000/app`) and it shows nothing:

```auto
Here is a image you need to imagine, because I encounter "Sorry, new users can only put one embedded media item in a post", and it does not allow a new member to post with images.

https://discuss.python.org/t/discourse-message-sorry-new-users-can-only-put-one-embedded-media-item-in-a-post/8037/1

```

## Issues

1. This approach will expose the Panel/Bokeh server in the HTML (what I do not intend to do).
2. The Panel server (`127.0.0.1:5000`) can be visited and it shows the list (what I do not intend to do).
3. Visiting the dashboard (e.g. `127.0.0.1:5000/app`) within the unintended Panel homepage, it shows nothing.

Is there any way to hide the Panel Server for users? Could I just run Panel without Bokeh server?

---

<div class="post-metadata">

**Author:** ![xareelee](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/xareelee/32/4894_2.png) [@xareelee](https://discourse.holoviz.org/u/xareelee)\
**Post date:** [May 11, 2023, 2:36pm UTC](https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334/2 "2023-05-11T14:36:20Z")

</div>

> [@xareelee](#):
>
> 127.0.0.1:8000/app2

 ![Screenshot 2023-05-11 at 21.50.42](https://discourse.holoviz.org/uploads/default/original/2X/f/f5d82fed1cec5a319a822d8a7b66ba598ee42b32.png)

---

<div class="post-metadata">

**Author:** ![xareelee](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/xareelee/32/4894_2.png) [@xareelee](https://discourse.holoviz.org/u/xareelee)\
**Post date:** [May 11, 2023, 2:37pm UTC](https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334/3 "2023-05-11T14:37:06Z")

</div>

> [@xareelee](#):
>
> `127.0.0.1:5000`,

 ![Screenshot 2023-05-11 at 21.44.48](https://discourse.holoviz.org/uploads/default/original/2X/e/e958f221f96c910d9d3fe9ea0ffbfce6f985f7f5.png)

---

<div class="post-metadata">

**Author:** ![xareelee](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/xareelee/32/4894_2.png) [@xareelee](https://discourse.holoviz.org/u/xareelee)\
**Post date:** [May 11, 2023, 2:38pm UTC](https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334/4 "2023-05-11T14:38:03Z")

</div>

> [@xareelee](#):
>
> 127.0.0.1:5000/app

 ![Screenshot 2023-05-11 at 21.55.44](https://discourse.holoviz.org/uploads/default/original/2X/1/1067c0552692ddbfc6625ae8c54349064e22e04f.png)

---

<div class="post-metadata">

**Author:** ![nghenzi](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/nghenzi/32/378_2.png) [@nghenzi](https://discourse.holoviz.org/u/nghenzi)\
**Post date:** [May 25, 2023, 10:29pm UTC](https://discourse.holoviz.org/t/how-to-do-the-best-practice-with-fastapi/5334/5 "2023-05-25T22:29:27Z")

</div>

If you put in allowed\_origin parameter only the fastapi address the panel site should refuse all other connections.
