Deployment
The Watchfire dashboard in production
Outside APP_ENV=local, /_watchfire is open only to signed-in users that the app's dashboard gate admits; without
a gate nobody gets in. A gate in app/agents/mod.rs that admits the users listed in an ADMIN_EMAILS key of
.env (a key of the app, read with env):
use crate::app::models::user::Model as User;
use smeltery::config::env;
use smeltery::watchfire::prelude::*;
pub fn register(w: &mut Watchfire) {
w.dashboard_gate(|auth, _app| async move {
let admins: String = env("ADMIN_EMAILS", "");
let Some(user) = auth.user::<User>().await? else {
return Ok(false);
};
Ok(admins.split(',').any(|email| email.trim() == user.email))
});
}
With ADMIN_EMAILS=ops@example.com in .env, that user signs in at /login and opens /_watchfire; other users
get 403, guests are sent to /login. WATCHFIRE_DASHBOARD=off removes the dashboard (404).
The JSON API under /_watchfire/api needs Authorization: Bearer <token> outside local development. On the server,
cd /srv/myapp && sudo -u myapp ./myapp agents:list (and agents:start|stop|pause|resume|restart|logs) call it
with the token, which they derive from APP_KEY. For other clients, agents:token prints the token (the hex
HMAC-SHA256 of watchfire-api keyed with APP_KEY, smeltery::watchfire::web::api_token) to standard output:
cd /srv/myapp && sudo -u myapp ./myapp agents:token
The token changes only with APP_KEY; a new APP_KEY revokes it (and signs every user out).