summaryrefslogtreecommitdiff
path: root/crates/chat-server/src/http.rs
diff options
context:
space:
mode:
authorDoan Luu Duc Tai <doan@luuduct.ai>2026-10-30 22:36:11 -0500
committerDoan Luu Duc Tai <doan@luuduct.ai>2026-10-30 22:36:11 -0500
commit6933ec28be3dac0dc17cd634c663db3b4818caad (patch)
tree22690260136d598d2719d97deb169b847b31424c /crates/chat-server/src/http.rs
parentc3b361c45ac8dd898d5c83a161abed5fc138b6c0 (diff)
Centralize deployment settings in the root environment file
Document public domains, ports, upstreams, chat binding, and backup defaults alongside private settings. Validate shared configuration and render Caddy, cgit, and website links from an explicit public allowlist while preserving one installation environment file.
Diffstat (limited to 'crates/chat-server/src/http.rs')
-rw-r--r--crates/chat-server/src/http.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/crates/chat-server/src/http.rs b/crates/chat-server/src/http.rs
index bb618d9..1c7286f 100644
--- a/crates/chat-server/src/http.rs
+++ b/crates/chat-server/src/http.rs
@@ -33,6 +33,7 @@ struct App {
permits: Arc<Semaphore>,
root: PathBuf,
origin: String,
+ public: std::collections::BTreeMap<String, String>,
}
fn secured(mut response: Response) -> Response {
@@ -129,22 +130,33 @@ async fn asset(State(app): State<App>, uri: axum::http::Uri) -> Response {
"/LICENSE" => ("LICENSE", "text/plain; charset=utf-8"),
_ => return secured(StatusCode::NOT_FOUND.into_response()),
};
- tokio::fs::read(app.root.join(path)).await.map_or_else(
- |_| secured(StatusCode::NOT_FOUND.into_response()),
- |bytes| secured(([("content-type", mime)], bytes).into_response()),
- )
+ let Ok(bytes) = tokio::fs::read(app.root.join(path)).await else {
+ return secured(StatusCode::NOT_FOUND.into_response());
+ };
+ if matches!(uri.path(), "/" | "/javascript.html") {
+ let rendered = String::from_utf8(bytes)
+ .map_err(anyhow::Error::from)
+ .and_then(|source| stack_config::render(&source, &app.public));
+ return rendered.map_or_else(
+ |_| secured(StatusCode::INTERNAL_SERVER_ERROR.into_response()),
+ |html| secured(([("content-type", mime)], html).into_response()),
+ );
+ }
+ secured(([("content-type", mime)], bytes).into_response())
}
pub(crate) async fn serve(
listener: tokio::net::TcpListener,
service: Service,
root: &Path,
+ public: std::collections::BTreeMap<String, String>,
) -> Result<()> {
let app = App {
origin: service.origin.clone(),
service: Arc::new(Mutex::new(service)),
permits: Arc::new(Semaphore::new(4)),
root: root.to_path_buf(),
+ public,
};
let routes = Router::new()
.route("/api", post(api))