prefect icon indicating copy to clipboard operation
prefect copied to clipboard

Unable to set URL prefix for server API

Open majikman111 opened this issue 1 year ago • 5 comments

First check

  • [X] I added a descriptive title to this issue.
  • [X] I used the GitHub search to find a similar issue and didn't find it.
  • [X] I searched the Prefect documentation for this issue.
  • [X] I checked that this issue is related to Prefect and not one of its dependencies.

Bug summary

I am running Prefect in a Kubernetes cluster behind an nginx reverse proxy and when setting the PREFECT_UI_SERVE_BASE setting the UI base path is updated but api base path is not, resulting in a rendered UI with no flow content. Additionally, updating the PREFECT_UI_API_URL setting changes what path the UI requests but not the path the api is actually served under.

Reproduction

1. Install Prefect
1. Apply settings `PREFECT_UI_SERVE_BASE=/root/` and `PREFECT_UI_API_URL=localhost:4200/root/api`
1. Run `prefect server start`
1. Browse to local prefect server at `localhost:4200/root`

The UI renders and api requests are sent to `localhost:4200/root/api` but fail (are being served from `localhost:4200/api`)

Error

No response

Versions

Version:               2.16.0
API version:           0.8.4
Python version:        3.11.8
Git commit:            17f42e9d
Built:                 Thu, Feb 22, 2024 3:45 PM
OS/Arch:               linux/x86_64
Profile:               default
Server type:           server

Additional context

Could potentially be solved by passing a configurable root_path argument to the FastAPI api_app object if available from settings here https://github.com/PrefectHQ/prefect/blob/main/src/prefect/server/api/server.py#L615

Related to #11472

majikman111 avatar Feb 27 '24 20:02 majikman111

Came across this recently. I'm currently rewriting prefix/api to /api using traefik rules. I agree it would be useful to have support for configuring the api to run at a path prefix too.

mthanded avatar Feb 28 '24 15:02 mthanded

I can confirm this. Frontend assets cannot be mapped from one path to the other with proxy, no matter the PREFECT_UI_URL setting.

tothandor avatar Aug 21 '24 14:08 tothandor

We will look into this, thank you all for raising and commenting

cicdw avatar Aug 21 '24 15:08 cicdw

Came across this recently. After set PREFECT_UI_URL, it still does not work.

Bear1110 avatar Aug 29 '24 06:08 Bear1110

Does anyone have a workaround for this? I'm pulling my hair out :)

radrichard avatar Oct 28 '24 18:10 radrichard

Hi guys, is this on the roadmap at all?

radrichard avatar Feb 03 '25 19:02 radrichard

Hey @radrichard sorry that we ghosted this issue - I've just opened a PR that should solve this; I'd love to get some confirmation from one of you that it indeed does before releasing! You can install off my branch with pip install git+https://github.com/prefecthq/prefect.git@root-path

cicdw avatar Feb 04 '25 22:02 cicdw

Hey @radrichard sorry that we ghosted this issue - I've just opened a PR that should solve this; I'd love to get some confirmation from one of you that it indeed does before releasing! You can install off my branch with pip install git+https://github.com/prefecthq/prefect.git@root-path

Thanks so much. I'll give it a go this weekend if that's OK?

radrichard avatar Feb 05 '25 22:02 radrichard

Yup that sounds good, thank you!

cicdw avatar Feb 05 '25 22:02 cicdw