cf7c71b8a3
Auth wall (Base.astro): set data-auth-pending on <body> at SSG time and hide
it with inline CSS before any JS runs; remove the attribute after /api/me
resolves. Eliminates the flash of protected content on private instances.
Multi-user write API (serve/server.py): the previous _apply_sidecar_edit and
strava_sync imports from bincio.edit.server were broken (those names don't
exist as module-level exports) and the Strava sync mutated a global data_dir,
making concurrent requests from different users racy. Fix: extract both
operations into bincio/edit/ops.py as pure functions that take data_dir
explicitly. Both edit/server.py and serve/server.py now import from there.
Security: add rate limiting to POST /api/register (5 attempts / 15 min / IP,
separate bucket from login). Add _check_id() activity ID validation to both
GET and POST /api/activity/{id} in serve/server.py.
Single-user mode: _write_root_manifest now forces instance.private=false when
no instance.db exists, even if a previous run wrote true. Prevents the auth
wall from firing and redirecting to /login/ when bincio serve isn't running.
ActivityFeed: skip filterHandle when profileIndexUrl is set (per-user profile
pages load the right shard directly; activities have no handle tag at that
point, so the filter was producing an empty feed). Fix handle links to point
to /u/{handle}/ instead of /{handle}/. Fix <a>-inside-<a> Svelte warning by
converting the inner handle link to a <button>.
55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
"""bincio serve — CLI entry point for the multi-user VPS server."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
import click
|
|
from rich.console import Console
|
|
|
|
console = Console()
|
|
|
|
|
|
@click.command("serve")
|
|
@click.option("--data-dir", required=True, type=click.Path(), help="BAS data directory (contains instance.db)")
|
|
@click.option("--site-dir", default=None, type=click.Path(), help="Astro site dir for post-write rebuilds")
|
|
@click.option("--host", default="127.0.0.1", help="Bind host (default: 127.0.0.1 — proxy via nginx)")
|
|
@click.option("--port", default=4041, help="Bind port (default: 4041)")
|
|
@click.option("--strava-client-id", default=None, envvar="STRAVA_CLIENT_ID", help="Strava OAuth client ID (enables per-user Strava sync)")
|
|
@click.option("--strava-client-secret", default=None, envvar="STRAVA_CLIENT_SECRET", help="Strava OAuth client secret")
|
|
def serve(data_dir: str, site_dir: Optional[str], host: str, port: int,
|
|
strava_client_id: Optional[str], strava_client_secret: Optional[str]) -> None:
|
|
"""Start the bincio multi-user application server.
|
|
|
|
Handles auth, user management, and write operations.
|
|
Intended to run behind nginx which serves static files.
|
|
|
|
Requires a data directory initialised with `bincio init`.
|
|
"""
|
|
import uvicorn
|
|
import bincio.serve.server as srv
|
|
|
|
dd = Path(data_dir).expanduser().resolve()
|
|
if not (dd / "instance.db").exists():
|
|
raise click.UsageError(
|
|
f"No instance.db found in {dd}. Run `bincio init --data-dir {dd}` first."
|
|
)
|
|
|
|
srv.data_dir = dd
|
|
if site_dir:
|
|
srv.site_dir = Path(site_dir).expanduser().resolve()
|
|
if strava_client_id:
|
|
srv.strava_client_id = strava_client_id
|
|
if strava_client_secret:
|
|
srv.strava_client_secret = strava_client_secret
|
|
|
|
console.print(f"[bold]bincio serve[/bold]")
|
|
console.print(f" Data: [cyan]{dd}[/cyan]")
|
|
if srv.site_dir:
|
|
console.print(f" Site: [cyan]{srv.site_dir}[/cyan]")
|
|
console.print(f" URL: [cyan]http://{host}:{port}[/cyan]")
|
|
console.print()
|
|
|
|
uvicorn.run(srv.app, host=host, port=port, log_level="info")
|