- The unlimited package is gone (easy to resell, e.g. by an astrologer): catalog, fair-use cap, UNLIMITED_DAILY_LIMIT, /v1/me unlimited_until, admin badge. Migration 0014 removes the 'unlimited' entitlements; old orders of it are skipped in the header. - New prices: single 2 000 Ft, couple 4 500, family 8 000, +1 synastry 2 500, +5 persons 1 500 (list prices 2 000 / 2 500 / 300). - Login page, packages page and the analysis offer say the analyses are written by top AI models, close to a professional astrologer's written reading, for a fraction of the price (the packages page names the model). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
165 lines
7.0 KiB
Rust
165 lines
7.0 KiB
Rust
//! Configuration from the environment.
|
|
|
|
use anyhow::{Context, bail};
|
|
|
|
/// Who may create an account.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum SignupMode {
|
|
/// Anyone.
|
|
Open,
|
|
/// Only invited addresses (or the holder of an invitation link).
|
|
Invite,
|
|
}
|
|
|
|
impl SignupMode {
|
|
pub fn as_str(self) -> &'static str {
|
|
match self {
|
|
SignupMode::Open => "open",
|
|
SignupMode::Invite => "invite",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Config {
|
|
/// `DATABASE_URL` (required).
|
|
pub database_url: String,
|
|
/// `HOROSCOPE_API_URL` (default `http://localhost:8080`).
|
|
pub horoscope_api_url: String,
|
|
/// `PUBLIC_BASE_URL`: the frontend's address, used in invitation and
|
|
/// e-mail links (default `http://localhost:3000`).
|
|
pub public_base_url: String,
|
|
/// `CORS_ALLOWED_ORIGINS`: comma-separated origins allowed to call the API
|
|
/// with cookies (default: `PUBLIC_BASE_URL`).
|
|
pub cors_allowed_origins: Vec<String>,
|
|
/// `COOKIE_SECURE` (default `true`); set `false` only for plain-HTTP development.
|
|
pub cookie_secure: bool,
|
|
/// `COOKIE_DOMAIN`: e.g. `.sorsfonalak.hu` to share the session between
|
|
/// the frontend and the API subdomain (default: host-only cookie).
|
|
pub cookie_domain: Option<String>,
|
|
/// `SESSION_TTL_DAYS` (default 30).
|
|
pub session_ttl_days: i64,
|
|
/// `PASSWORD_LOGIN` (default `false`): e-mail and password registration and
|
|
/// login. Off in production, where only Google, Apple and Facebook are offered.
|
|
pub password_login: bool,
|
|
/// `MOCK_PAYMENTS` (default `false`): a stand-in payment that adds an
|
|
/// analysis unit at once, until Stripe is connected.
|
|
pub mock_payments: bool,
|
|
/// `GOOGLE_CLIENT_IDS`: comma-separated OAuth client ids accepted as the
|
|
/// ID token audience; empty disables Google login.
|
|
pub google_client_ids: Vec<String>,
|
|
/// `GOOGLE_JWKS_URL` (default Google's certificate endpoint).
|
|
pub google_jwks_url: String,
|
|
/// `BOOTSTRAP_ADMIN_EMAILS`: these users get the admin role when they
|
|
/// register or log in (to create the first administrator).
|
|
pub bootstrap_admin_emails: Vec<String>,
|
|
/// `SUPPORTED_LOCALES` (default `hu,en`); the first is the default.
|
|
pub supported_locales: Vec<String>,
|
|
/// `ANALYSIS_MODEL`: writes the paid detailed analyses (default
|
|
/// `anthropic/claude-opus-5.5`, the best of the 2026-11 comparison).
|
|
pub analysis_model: String,
|
|
/// `SUMMARY_MODEL`: writes the free short summary of every saved chart
|
|
/// (default `anthropic/claude-sonnet-5.5`, about 1 US cent each).
|
|
pub summary_model: String,
|
|
/// `ANALYSIS_PROMPT_VERSION` (default `v2`); part of the analysis cache key.
|
|
pub prompt_version: String,
|
|
/// `MAX_CHARTS_PER_USER` (default 1000): a safety cap.
|
|
pub max_charts_per_user: i64,
|
|
/// `FREE_PERSON_SLOTS` (default 0): persons a user may add without a package.
|
|
pub free_person_slots: i64,
|
|
/// `SIGNUP_MODE` (`invite` or `open`, default `invite`): whether new
|
|
/// accounts need an invitation.
|
|
pub signup_mode: SignupMode,
|
|
}
|
|
|
|
fn var(name: &str) -> Option<String> {
|
|
std::env::var(name).ok().map(|v| v.trim().to_string()).filter(|v| !v.is_empty())
|
|
}
|
|
|
|
fn list(name: &str) -> Vec<String> {
|
|
var(name)
|
|
.map(|v| v.split(',').map(|s| s.trim().to_string()).filter(|s| !s.is_empty()).collect())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
fn parsed<T: std::str::FromStr>(name: &str, default: T) -> anyhow::Result<T>
|
|
where
|
|
T::Err: std::fmt::Display,
|
|
{
|
|
match var(name) {
|
|
Some(v) => v.parse().map_err(|e| anyhow::anyhow!("invalid {name} '{v}': {e}")),
|
|
None => Ok(default),
|
|
}
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_env() -> anyhow::Result<Self> {
|
|
let public_base_url =
|
|
var("PUBLIC_BASE_URL").unwrap_or_else(|| "http://localhost:3000".into()).trim_end_matches('/').to_string();
|
|
let mut cors_allowed_origins = list("CORS_ALLOWED_ORIGINS");
|
|
if cors_allowed_origins.is_empty() {
|
|
cors_allowed_origins.push(public_base_url.clone());
|
|
}
|
|
let mut supported_locales = list("SUPPORTED_LOCALES");
|
|
if supported_locales.is_empty() {
|
|
supported_locales = vec!["hu".into(), "en".into()];
|
|
}
|
|
let config = Self {
|
|
database_url: var("DATABASE_URL").context("DATABASE_URL is required")?,
|
|
horoscope_api_url: var("HOROSCOPE_API_URL").unwrap_or_else(|| "http://localhost:8080".into()),
|
|
public_base_url,
|
|
cors_allowed_origins,
|
|
cookie_secure: parsed("COOKIE_SECURE", true)?,
|
|
cookie_domain: var("COOKIE_DOMAIN"),
|
|
session_ttl_days: parsed("SESSION_TTL_DAYS", 30)?,
|
|
password_login: parsed("PASSWORD_LOGIN", false)?,
|
|
mock_payments: parsed("MOCK_PAYMENTS", false)?,
|
|
google_client_ids: list("GOOGLE_CLIENT_IDS"),
|
|
google_jwks_url: var("GOOGLE_JWKS_URL")
|
|
.unwrap_or_else(|| "https://www.googleapis.com/oauth2/v3/certs".into()),
|
|
bootstrap_admin_emails: list("BOOTSTRAP_ADMIN_EMAILS").into_iter().map(|e| e.to_lowercase()).collect(),
|
|
supported_locales,
|
|
analysis_model: var("ANALYSIS_MODEL").unwrap_or_else(|| "anthropic/claude-opus-5.5".into()),
|
|
summary_model: var("SUMMARY_MODEL").unwrap_or_else(|| "anthropic/claude-sonnet-5.5".into()),
|
|
prompt_version: var("ANALYSIS_PROMPT_VERSION").unwrap_or_else(|| "v2".into()),
|
|
max_charts_per_user: parsed("MAX_CHARTS_PER_USER", 1000)?,
|
|
free_person_slots: parsed("FREE_PERSON_SLOTS", 0)?,
|
|
signup_mode: match var("SIGNUP_MODE").as_deref() {
|
|
None | Some("invite") => SignupMode::Invite,
|
|
Some("open") => SignupMode::Open,
|
|
Some(other) => bail!("invalid SIGNUP_MODE '{other}': use 'invite' or 'open'"),
|
|
},
|
|
};
|
|
if config.session_ttl_days < 1 {
|
|
bail!("SESSION_TTL_DAYS must be at least 1");
|
|
}
|
|
Ok(config)
|
|
}
|
|
|
|
/// Defaults for tests.
|
|
#[cfg(test)]
|
|
pub fn for_tests(database_url: String, horoscope_api_url: String, google_jwks_url: String) -> Self {
|
|
Self {
|
|
database_url,
|
|
horoscope_api_url,
|
|
public_base_url: "https://sorsfonalak.test".into(),
|
|
cors_allowed_origins: vec!["https://sorsfonalak.test".into()],
|
|
cookie_secure: true,
|
|
cookie_domain: None,
|
|
session_ttl_days: 30,
|
|
password_login: true,
|
|
mock_payments: true,
|
|
google_client_ids: vec!["test-client.apps.googleusercontent.com".into()],
|
|
google_jwks_url,
|
|
bootstrap_admin_emails: vec!["admin@example.com".into()],
|
|
supported_locales: vec!["hu".into(), "en".into()],
|
|
analysis_model: "anthropic/claude-test".into(),
|
|
summary_model: "anthropic/claude-summary".into(),
|
|
prompt_version: "v1".into(),
|
|
max_charts_per_user: 50,
|
|
free_person_slots: 5,
|
|
signup_mode: SignupMode::Open,
|
|
}
|
|
}
|
|
}
|