Forum: a service of its own and the /forum pages

services/forum (axum, port 8083) on the same database and login, in the
forum schema (migration 0038, which also adds the moderator role):
nicknames, profiles with shared signs, topics, threads with listening or
advice intent, two-level replies, read marks and followed threads,
reactions as ratings with points and ranks, newcomer limits (lifted by a
purchase), moderation with reasons, bans and a log. Integration tests run
in CI.

The frontend's /forum pages (light by default, dark on request, phone
first with a desktop layout) are switched on by FORUM_URL; the /api/v1
proxy sends /api/v1/forum/* to the forum service. Concept and status:
docs/kozosseg.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 10:29:49 +00:00
co-authored by Claude Opus 5.5
parent fa46dcb757
commit 36b38525c3
52 changed files with 6782 additions and 11 deletions
+55
View File
@@ -0,0 +1,55 @@
//! Sorsfonalak forum: pseudonymous members, topics, threads, posts,
//! reactions, read marks, followed threads and moderation (docs/kozosseg.md).
//!
//! A service of its own, so it can be scaled apart from the backend. It shares
//! the database and the login: a session of the backend (`sf_session` cookie
//! or `Authorization: Bearer`) is valid here too.
//!
//! Configuration: `DATABASE_URL`; `BIND_ADDR` (default `0.0.0.0:8083`),
//! `LOG_FORMAT`, `RUST_LOG`, `LOG_DIR`. Database migrations run at startup.
//!
//! `forum healthcheck` performs a local health check (for Docker).
mod auth;
mod error;
mod rank;
mod routes;
#[cfg(test)]
mod tests;
mod text;
use std::sync::Arc;
use anyhow::Context;
use sqlx::PgPool;
const DEFAULT_BIND_ADDR: &str = "0.0.0.0:8083";
pub struct AppState {
pub db: PgPool,
/// Seconds a member waits between two posts (0 in the tests).
pub flood_secs: i32,
}
impl AppState {
pub fn new(db: PgPool) -> Self {
Self { db, flood_secs: 5 }
}
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let addr = service_kit::bind_addr(DEFAULT_BIND_ADDR)?;
if std::env::args().nth(1).as_deref() == Some("healthcheck") {
return service_kit::healthcheck(addr);
}
let _log = service_kit::init_logging("forum");
let url = std::env::var("DATABASE_URL").context("DATABASE_URL is not set")?;
let pool = db::connect(&url).await.context("connecting to the database")?;
db::migrate(&pool).await.context("running database migrations")?;
let app = routes::router(Arc::new(AppState::new(pool)));
let listener = tokio::net::TcpListener::bind(addr).await.with_context(|| format!("binding {addr}"))?;
tracing::info!(%addr, "listening");
axum::serve(listener, app).with_graceful_shutdown(service_kit::shutdown_signal()).await?;
Ok(())
}