Skip to content

Commit c8b2080

Browse files
committed
fix: Fix issue when user specifies a port for feast ui
Signed-off-by: Danny Chiao <danny@tecton.ai>
1 parent b3ba8aa commit c8b2080

3 files changed

Lines changed: 40 additions & 31 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"projects": [
3+
{
4+
"name": "Project",
5+
"description": "Test project",
6+
"id": "project_id",
7+
"registryPath": "http://0.0.0.0:8888/registry"
8+
}
9+
]
10+
}
11+

sdk/python/feast/ui/src/index.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
import React from 'react';
1+
import React from "react";
22
import ReactDOM from "react-dom";
3-
import './index.css';
3+
import "./index.css";
44
import FeastUI from "@feast-dev/feast-ui";
55
import "@feast-dev/feast-ui/dist/feast-ui.css";
66

77
ReactDOM.render(
88
<React.StrictMode>
9-
<FeastUI
10-
feastUIConfigs={{
11-
projectListPromise: fetch("http://0.0.0.0:8888/projects-list", {
12-
headers: {
13-
"Content-Type": "application/json",
14-
},
15-
}).then((res) => {
16-
return res.json();
17-
})
18-
}}
19-
/>
9+
<FeastUI />
2010
</React.StrictMode>,
2111
document.getElementById("root")
22-
);
12+
);

sdk/python/feast/ui_server.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import threading
33
from typing import Callable, Optional
44

5-
import pkg_resources
5+
from importlib_resources import files, as_file
66
import uvicorn
77
from fastapi import FastAPI, Response
88
from fastapi.middleware.cors import CORSMiddleware
@@ -16,8 +16,10 @@ def get_app(
1616
get_registry_dump: Callable,
1717
project_id: str,
1818
registry_ttl_secs: int,
19+
host: str,
20+
port: int,
1921
):
20-
ui_dir = pkg_resources.resource_filename(__name__, "ui/build/")
22+
ui_dir = files(__package__).joinpath("ui/build/")
2123

2224
app = FastAPI()
2325

@@ -53,25 +55,30 @@ def shutdown_event():
5355

5456
async_refresh()
5557

56-
@app.get("/registry")
57-
def read_registry():
58-
return json.loads(registry_json)
59-
60-
# Generate projects-list json that points to the current repo's project
61-
# TODO(adchia): Enable users to also add project name + description fields in feature_store.yaml
62-
@app.get("/projects-list")
63-
def projects_list():
64-
projects = {
58+
# Initialize with the projects-list.json file
59+
try:
60+
f = ui_dir.joinpath("projects-list.json").open(mode="w")
61+
projects_dict = {
6562
"projects": [
6663
{
6764
"name": "Project",
6865
"description": "Test project",
6966
"id": project_id,
70-
"registryPath": "http://0.0.0.0:8888/registry",
67+
"registryPath": f"http://{host}:{port}/registry",
7168
}
7269
]
7370
}
74-
return projects
71+
f.write(json.dumps(projects_dict))
72+
except Exception as e:
73+
raise RuntimeError(
74+
"Failed to initialize projects-list.json with registry path"
75+
) from e
76+
finally:
77+
f.close()
78+
79+
@app.get("/registry")
80+
def read_registry():
81+
return json.loads(registry_json)
7582

7683
# For all other paths (such as paths that would otherwise be handled by react router), pass to React
7784
@app.api_route("/p/{path_name:path}", methods=["GET"])
@@ -83,9 +90,10 @@ def catch_all():
8390

8491
return Response(content, media_type="text/html")
8592

86-
app.mount(
87-
"/", StaticFiles(directory=ui_dir, html=True), name="site",
88-
)
93+
with as_file(ui_dir) as react_app_dir:
94+
app.mount(
95+
"/", StaticFiles(directory=react_app_dir, html=True), name="site",
96+
)
8997

9098
return app
9199

@@ -98,5 +106,5 @@ def start_server(
98106
project_id: str,
99107
registry_ttl_sec: int,
100108
):
101-
app = get_app(store, get_registry_dump, project_id, registry_ttl_sec)
109+
app = get_app(store, get_registry_dump, project_id, registry_ttl_sec, host, port)
102110
uvicorn.run(app, host=host, port=port)

0 commit comments

Comments
 (0)