Skip to content

Commit 4586f75

Browse files
Merge pull request #16 from goldlabelapps/staging
This pull request introduces several improvements to the FastAPI application, focusing on environment variable handling, API metadata, static file serving, and documentation.
2 parents 70e7571 + afc262c commit 4586f75

4 files changed

Lines changed: 24 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
> FastAPI/Python/Postgres/tsvector.
44
Open Source, production ready Python FastAPI/Postgres app for [NX](https://goldlabel.pro?s=python-nx-ai)
55

6-
#### Use
7-
8-
`uvicorn app.main:app`
6+
```sh
7+
uvicorn app.main:app --reload
8+
```
99

1010
#### Install
1111

app/api/products.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ def root() -> dict:
3333
]
3434
cur.close()
3535
conn.close()
36+
37+
load_dotenv()
38+
base_url = os.getenv("BASE_URL", "http://localhost:8000")
39+
3640
epoch = int(time.time() * 1000)
3741
meta = {
3842
"version": __version__,
43+
"base_url": base_url,
3944
"time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),
4045
"epoch": epoch,
4146
"severity": "success",

app/api/root.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from app import __version__
22
from fastapi import APIRouter
33
import os, time
4-
import psycopg2
54
from dotenv import load_dotenv
65
from app import __version__
76

@@ -14,14 +13,15 @@ def root() -> dict:
1413
base_url = os.getenv("BASE_URL", "http://localhost:8000")
1514
epoch = int(time.time() * 1000)
1615
meta = {
16+
"base_url": base_url,
1717
"version": __version__,
1818
"time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()),
1919
"epoch": epoch,
2020
"severity": "success",
2121
"message": f"NX AI says hello",
22-
"base_url": base_url
2322
}
2423
endpoints = [
24+
{"docs": "docs", "url": f"{base_url}/docs"},
2525
{"name": "health", "url": f"{base_url}/health"},
2626
{"name": "products", "url": f"{base_url}/products"}
2727
]

app/main.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from app import __version__
22
"""NX AI - FastAPI entry point."""
33

4+
45
from fastapi import FastAPI
6+
from fastapi.staticfiles import StaticFiles
7+
from fastapi.responses import FileResponse
8+
import os
59

610
from app import __version__
711
from app.api.routes import router
@@ -12,4 +16,14 @@
1216
version=__version__,
1317
)
1418

19+
1520
app.include_router(router)
21+
22+
# Mount static directory
23+
app.mount("/static", StaticFiles(directory=os.path.join(os.path.dirname(__file__), "static")), name="static")
24+
25+
# Favicon route
26+
@app.get("/favicon.ico", include_in_schema=False)
27+
async def favicon():
28+
favicon_path = os.path.join(os.path.dirname(__file__), "static", "favicon.ico")
29+
return FileResponse(favicon_path)

0 commit comments

Comments
 (0)