Skip to content

Commit 3e8a332

Browse files
fix(frontend): move frontend to main repo
1 parent 58df7b1 commit 3e8a332

12 files changed

Lines changed: 5718 additions & 41 deletions

File tree

api/app.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@
44

55
from litestar import Litestar, get
66
from litestar.config.cors import CORSConfig
7-
from litestar.contrib.jinja import JinjaTemplateEngine
87
from litestar.openapi.config import OpenAPIConfig
98
from litestar.openapi.plugins import SwaggerRenderPlugin
10-
from litestar.response import Template
9+
from litestar.response import Redirect
1110
from litestar.static_files import create_static_files_router
12-
from litestar.template.config import TemplateConfig
1311

1412
from .db import close_pool, ensure_schema, open_pool
1513
from .queries import fetch_state
1614
from .routers.hashtag import v2_router
1715
from .schemas import HealthResponse
1816

19-
TEMPLATES = Path(__file__).parent / "templates"
2017
FRONTEND_DIST = os.getenv("FRONTEND_DIST")
2118
DEFAULT_CORS_ORIGINS = (
2219
"http://localhost:5173",
@@ -48,13 +45,14 @@ async def lifespan(app: Litestar):
4845

4946

5047
@get("/", include_in_schema=False)
51-
async def home() -> Template:
52-
return Template("home.html")
48+
async def home() -> Redirect:
49+
return Redirect(path="/docs")
5350

5451

5552
def _root_handlers() -> list:
56-
"""Serve the built frontend at / when FRONTEND_DIST is a directory, else the API home page. Explicit API
57-
routes (/health, /api/*, /docs) take precedence over the static catch-all; html_mode serves index.html."""
53+
"""Serve the built frontend at / when FRONTEND_DIST is a directory, else redirect to the API docs.
54+
Explicit API routes (/health, /api/*, /docs) take precedence over the static catch-all; html_mode
55+
serves index.html."""
5856
if FRONTEND_DIST and Path(FRONTEND_DIST).is_dir():
5957
return [create_static_files_router(path="/", directories=[FRONTEND_DIST], html_mode=True)]
6058
return [home]
@@ -88,5 +86,4 @@ async def health() -> HealthResponse:
8886
path="/docs",
8987
render_plugins=[SwaggerRenderPlugin()],
9088
),
91-
template_config=TemplateConfig(directory=TEMPLATES, engine=JinjaTemplateEngine), # ty: ignore[invalid-argument-type]
9289
)

api/templates/home.html

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/infra.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ api.osmsg.<domain> A <server-ip>
3838

3939
## Configure and deploy
4040

41+
The frontend ships in this repo under `frontend/`, and Caddy serves it from `../frontend` relative to
42+
the compose file. Clone the repo to `/opt/osmsg` so `infra/` and `frontend/` sit side by side.
43+
4144
```bash
45+
sudo git clone https://github.com/osgeonepal/osmsg.git /opt/osmsg
46+
cd /opt/osmsg
4247
cp infra/.env.example infra/.env && $EDITOR infra/.env # set the two domains + ACME email
43-
sudo mkdir -p /opt/osmsg/infra
44-
sudo cp infra/docker-compose.yml infra/Caddyfile infra/osmsg.service infra/.env /opt/osmsg/infra/
45-
sudo git clone https://github.com/osgeonepal/osmsg-leaderboard.git /opt/osmsg-leaderboard
46-
sudo cp /opt/osmsg/infra/osmsg.service /etc/systemd/system/ && sudo systemctl daemon-reload
48+
sudo cp infra/osmsg.service /etc/systemd/system/ && sudo systemctl daemon-reload
4749
sudo systemctl enable --now osmsg
4850
```
4951

52+
Deploy updates with `git -C /opt/osmsg pull` (refreshes both the frontend and the compose files);
53+
`infra/.env` and any `infra/docker-compose.override.yml` are gitignored and stay untouched.
54+
5055
`OSMSG_EXTRA_ARGS` runs every tick. Do not put `--last`, `--days`, `--update`, or `--url` there: the
5156
worker adds `--update` and auto-selects granularity from the gap (day to hour to minute). Pinning
5257
`--url minute` over a large gap crawls tens of thousands of files and fills the disk.

frontend/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# osmsg leaderboard frontend
2+
3+
Static single-page leaderboard for the osmsg API. No build step: plain HTML, CSS, and JavaScript.
4+
Tailwind, lucide, and flatpickr load from a CDN at runtime.
5+
6+
## Files
7+
8+
- `index.html` , page markup and CDN includes.
9+
- `app.js` , query flow, state, rendering, CSV export.
10+
- `charts.js` , the trending-hashtags and editors lists.
11+
- `style.css` , all styling (light and dark).
12+
- `sw.js` , service worker (Workbox): network-first for the app shell and API, long-lived CDN cache.
13+
- `manifest.webmanifest` , PWA manifest.
14+
- `tailwind.config.js` , Tailwind CDN configuration.
15+
16+
## API origin
17+
18+
`app.js` reads the API base from `window.OSMSG_API_BASE`, falling back to `window.location.origin`.
19+
In production Caddy serves this site and reverse-proxies `/api/*`, `/health`, `/docs`, and `/schema`
20+
to the API on the same origin, so no per-deploy edit is needed.
21+
22+
## Local preview
23+
24+
Serve the directory with any static server and point it at a running API:
25+
26+
```sh
27+
python -m http.server -d frontend 8080
28+
```
29+
30+
Open <http://localhost:8080>. Set `window.OSMSG_API_BASE` in the console or a small inline script if
31+
the API runs on a different origin.
32+
33+
## Deployment
34+
35+
The production Caddy service bind-mounts this directory read-only at `/srv/leaderboard`
36+
(`infra/docker-compose.yml`). See `docs/infra.md` for the full deployment.

0 commit comments

Comments
 (0)