Files
sorsfonalak/services/horoscope-api/src/main.rs
T
fecoandClaude Opus 5.5 699ce2abbd
CI / test (push) Successful in 2m6s
CI / build (push) Skipped
CI / deploy (push) Skipped
Moon and retrograde calendars, "today in the sky" on the own chart
New public pages: /holdnaptar (new and full moons, quarters, eclipses and
the Moon's sign changes, month by month, with the Moon of today) and
/retrograd (the retrograde periods of Mercury to Pluto with their shadows,
and which planets are retrograde now), each with a page per year around
the current one. The own chart gets a "Ma az égen" card: the Moon's sign,
phase and natal house, the tightest transits to the chart in fixed
sentences, and the retrograde planets. No AI, nothing stored.

The events come from astro-engine (sampling and bisection, checked against
swetest and the 2026 eclipses) through horoscope-api GET /v1/sky and
/v1/sky/events; the backend serves them at /v1/public/sky… and keeps them
in memory (the sky now for five minutes, a year's events for good). Links
in the mobile menu, the footer, the sitemap and the free tools on the home
page; the desktop header is unchanged (it is full at 1280 px).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-23 17:21:36 +00:00

66 lines
2.2 KiB
Rust

//! Natal chart and synastry HTTP API.
//!
//! Configuration (environment):
//! * `ASTRO_DATA_DIR` directory with `ephe/`, `zoneinfo/`, `geonames/` (default `./data`)
//! * `BIND_ADDR` listen address (default `0.0.0.0:8080`)
//! * `CORS_ALLOWED_ORIGINS` `*` (default) or a comma-separated list of origins
//! * `LOG_FORMAT` `text` (default) or `json`; `RUST_LOG` sets the level
//!
//! `horoscope-api healthcheck` performs a local health check (for Docker).
mod error;
mod forecast;
mod natal;
mod routes;
mod sky;
mod synastry;
#[cfg(test)]
mod tests;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Instant;
use anyhow::Context;
use astro_engine::Ephemeris;
use astro_engine::swiss::SwissEphemeris;
use geo_tz::Atlas;
pub struct AppState {
pub engine: Arc<dyn Ephemeris>,
pub atlas: Atlas,
}
const DEFAULT_BIND_ADDR: &str = "0.0.0.0:8080";
fn load_state() -> anyhow::Result<AppState> {
let data_dir = PathBuf::from(std::env::var("ASTRO_DATA_DIR").unwrap_or_else(|_| "data".into()));
let started = Instant::now();
let engine = SwissEphemeris::new(data_dir.join("ephe"))
.with_context(|| format!("loading ephemeris from {}", data_dir.join("ephe").display()))?;
let atlas = Atlas::load(&data_dir).with_context(|| format!("loading data from {}", data_dir.display()))?;
tracing::info!(
places = atlas.places.len(),
tzdb = %atlas.zones.version,
ephemeris = %engine.info().version,
elapsed_ms = started.elapsed().as_millis() as u64,
"data loaded"
);
Ok(AppState { engine: Arc::new(engine), atlas })
}
#[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("horoscope-api");
let state = Arc::new(tokio::task::spawn_blocking(load_state).await??);
let app = routes::router(state);
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(())
}