Skip to content

Commit afc262c

Browse files
committed
Add static assets, favicon, and base_url meta
Mount static files and serve a favicon in FastAPI, add BASE_URL to API metadata, and update README run command. main.py: import StaticFiles/FileResponse/os, mount /static to app/static and add a /favicon.ico route. app/api/products.py: load dotenv and include base_url (from BASE_URL env, default http://localhost:8000) in the response meta. README.md: show the uvicorn start command with --reload in a shell code block for local development.
1 parent 24f09a8 commit afc262c

3 files changed

Lines changed: 22 additions & 3 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/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)