feat: resolve request paths within contained site roots

This commit is contained in:
randogoth 2026-10-04 19:08:33 +03:00
parent 6a3a198975
commit 3031b8acdd
9 changed files with 1257 additions and 8 deletions

View file

@ -11,6 +11,7 @@ use std::path::Path;
use anyhow::{Context, Result};
use itsybitsy_core::config::{Checked, ServerConfig};
use itsybitsy_core::siteset::SiteSet;
use crate::cli::Cli;
@ -28,24 +29,28 @@ pub fn run(cli: &Cli) -> Result<()> {
/// Takes the format set rather than reading [`registry`] directly, so a test can
/// supply the ids a later milestone's registry will provide.
pub fn check(config_path: &Path, formats: &[&str]) -> Result<()> {
let (config, checked) = load(config_path, formats)?;
report(&config, &checked);
let (config, checked, sites) = load(config_path, formats)?;
report(&config, &checked, &sites);
Ok(())
}
fn load(config_path: &Path, formats: &[&str]) -> Result<(ServerConfig, Checked)> {
fn load(config_path: &Path, formats: &[&str]) -> Result<(ServerConfig, Checked, SiteSet)> {
// No context on load: its errors already name the file.
let config = ServerConfig::load(config_path)?;
let checked = config
.validate(config_path, formats)
.with_context(|| format!("validating {}", config_path.display()))?;
Ok((config, checked))
// Opening every root here means a broken site fails at startup rather than
// on the first request that happens to name it.
let sites = SiteSet::build(&config)
.with_context(|| format!("opening the sites in {}", config_path.display()))?;
Ok((config, checked, sites))
}
/// What `--check` prints: the resolved routing, so an operator can see which
/// name reaches which folder without sending a request.
fn report(config: &ServerConfig, checked: &Checked) {
println!("sites:");
fn report(config: &ServerConfig, checked: &Checked, sites: &SiteSet) {
println!("sites: {} configured, {} distinct roots", checked.roots.len(), sites.len());
for (name, root) in &checked.roots {
println!(" {name}: {}", root.display());
}