forked from feast-dev/feast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_server.py
More file actions
64 lines (49 loc) · 1.79 KB
/
Copy pathui_server.py
File metadata and controls
64 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import pkg_resources
import uvicorn
from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
import feast
def get_app(store: "feast.FeatureStore", registry_dump: str, project_id: str):
ui_dir = pkg_resources.resource_filename(__name__, "ui/build/")
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/registry")
def read_registry():
return json.loads(registry_dump)
# Generate projects-list json that points to the current repo's project
# TODO(adchia): Enable users to also add project name + description fields in feature_store.yaml
@app.get("/projects-list")
def projects_list():
projects = {
"projects": [
{
"name": "Project",
"description": "Test project",
"id": project_id,
"registryPath": "http://0.0.0.0:8888/registry",
}
]
}
return projects
# For all other paths (such as paths that would otherwise be handled by react router), pass to React
@app.api_route("/p/{path_name:path}", methods=["GET"])
def catch_all():
filename = ui_dir + "index.html"
with open(filename) as f:
content = f.read()
return Response(content, media_type="text/html")
app.mount(
"/", StaticFiles(directory=ui_dir, html=True), name="site",
)
return app
def start_server(store: "feast.FeatureStore", registry_dump: str, project_id: str):
app = get_app(store, registry_dump, project_id)
uvicorn.run(app, host="0.0.0.0", port=8888)