-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (27 loc) · 817 Bytes
/
main.py
File metadata and controls
37 lines (27 loc) · 817 Bytes
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
import webbrowser
from pathlib import Path
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi_forge.core.build import build_fastapi_project
from fastapi_forge.schemas import ProjectSpec
app = FastAPI()
def start_forge_api() -> None:
app.mount(
"/",
StaticFiles(
directory=Path(__file__).parent.parent / "static",
html=True,
),
name="frontend",
)
webbrowser.open("http://localhost:8000")
uvicorn.run(app, host="localhost", port=8000)
@app.post("/generate")
async def generate_project(project_spec: ProjectSpec) -> None:
try:
await build_fastapi_project(project_spec, dry_run=False)
except Exception as e:
print(e)
if __name__ == "__main__":
start_forge_api()