yumechi-no-kuni/yume-mods/nyuukyou/src/main.rs

67 lines
1.6 KiB
Rust
Raw Normal View History

use std::path::PathBuf;
use std::sync::Arc;
use axum::response::IntoResponse;
use clap::Parser;
use fedivet::evaluate::chain::audit::AuditOptions;
use fedivet::evaluate::Evaluator;
use fedivet::model::error::MisskeyError;
use fedivet::serve;
use fedivet::BaseAppState;
use fedivet::HasAppState;
use serde::Serialize;
#[derive(Parser)]
pub struct Args {
#[clap(short, long, default_value = "127.0.0.1:3001")]
pub listen: String,
#[clap(short, long, default_value = "http://web:3000")]
pub backend: String,
#[clap(long)]
pub tls_cert: Option<String>,
#[clap(long)]
pub tls_key: Option<String>,
}
#[allow(clippy::unused_async)]
async fn build_state<E: IntoResponse + Clone + Serialize + Send + Sync + 'static>(
base: Arc<BaseAppState<E>>,
_args: &Args,
) -> impl HasAppState<E> + Evaluator<E> {
base
.extract_meta()
.audited(AuditOptions::new(PathBuf::from("/store/log/audit/incoming")))
}
#[tokio::main]
async fn main() {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info");
}
env_logger::init();
let args = Args::parse();
let state = build_state::<MisskeyError>(
Arc::new(
BaseAppState::new(args.backend.parse().expect("Invalid backend URL")).with_empty_ctx(),
),
&args,
)
.await;
serve::run(
state.clone(),
serve::start(
state,
&args.listen,
Some("/store/log/panic.log"),
args.tls_cert.as_deref(),
args.tls_key.as_deref(),
)
.await,
)
.await;
}