Skip to content

Commit

Permalink
Enhancement: /ui-settings subpathing (PrefectHQ#11701)
Browse files Browse the repository at this point in the history
  • Loading branch information
znicholasbrown authored Jan 25, 2024
1 parent db5e8f9 commit 9e0252b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/prefect/server/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ async def orion_info():

def create_ui_app(ephemeral: bool) -> FastAPI:
ui_app = FastAPI(title=UI_TITLE)
ui_app.add_middleware(GZipMiddleware)
base_url = prefect.settings.PREFECT_UI_SERVE_BASE.value()
stripped_base_url = base_url.rstrip("/")
static_dir = (
prefect.settings.PREFECT_UI_STATIC_DIRECTORY.value()
or prefect.__ui_static_subpath__
Expand All @@ -348,7 +348,7 @@ def create_ui_app(ephemeral: bool) -> FastAPI:
mimetypes.init()
mimetypes.add_type("application/javascript", ".js")

@ui_app.get("/ui-settings")
@ui_app.get(f"{stripped_base_url}/ui-settings")
def ui_settings():
return {
"api_url": prefect.settings.PREFECT_UI_API_URL.value(),
Expand All @@ -375,7 +375,7 @@ def create_ui_static_subpath():
replace_placeholder_string_in_files(
static_dir,
"/PREFECT_UI_SERVE_BASE_REPLACE_PLACEHOLDER",
base_url.rstrip("/"),
stripped_base_url,
)

# Create a file to indicate that the static files have been copied
Expand All @@ -384,6 +384,8 @@ def create_ui_static_subpath():
with open(os.path.join(static_dir, reference_file_name), "w") as f:
f.write(base_url)

ui_app.add_middleware(GZipMiddleware)

if (
os.path.exists(prefect.__ui_static_path__)
and prefect.settings.PREFECT_UI_ENABLED.value()
Expand Down
2 changes: 1 addition & 1 deletion ui/src/services/uiSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class UiSettings {
public static settings: Settings | null = null

private static promise: Promise<Settings> | null = null
private static readonly baseUrl = MODE() === 'development' ? 'http://127.0.0.1:4200' : ''
private static readonly baseUrl = MODE() === 'development' ? 'http://127.0.0.1:4200' : BASE_URL()
public static async load(): Promise<Settings> {
if (this.settings !== null) {
return this.settings
Expand Down

0 comments on commit 9e0252b

Please sign in to comment.