summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/main.rs b/src/main.rs
index a17e2b2..edf8be1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,47 +1,47 @@
-use crate::error::TwinHError;
-use hyper::{
- service::{make_service_fn, service_fn},
- Server,
-};
-use log::LevelFilter;
-
-#[macro_use]
-extern crate lazy_static;
+use anyhow::Result;
+use log::{debug, error};
+use std::env;
+use std::io::prelude::*;
mod config;
-mod error;
-mod import;
-mod models;
-mod repo;
-mod routes;
mod templates;
-#[tokio::main]
-async fn main() -> Result<(), TwinHError> {
- // configure logger
- let level = match config::INSTANCE.verbose {
- 1 => LevelFilter::Info,
- 2 => LevelFilter::Debug,
- _ => LevelFilter::Warn,
- };
- env_logger::builder().filter_level(level).init();
-
- // create HTTP listener
- let make_svc =
- make_service_fn(move |_conn| async { Ok::<_, TwinHError>(service_fn(routes::router)) });
-
- // bind server with signal
- let server = Server::bind(&config::INSTANCE.bind_addr.into()).serve(make_svc);
- let graceful = server.with_graceful_shutdown(shutdown_signal());
-
- // start and wait for shutdown
- graceful.await?;
- Ok(())
+fn main() {
+ if let Err(e) = || -> Result<()> {
+ env_logger::Builder::from_env(config::LOGLEVEL).init();
+ let config = config::init()?;
+
+ let reg = templates::init();
+ let vars = env::vars();
+
+ let mut input = String::new();
+ std::io::stdin().read_to_string(&mut input).unwrap();
+ debug!("Final starting input: {input}");
+ debug!("Final starting config: {:?}", config);
+
+ if (env::var("PATH_INFO")? == "/status") {
+ status();
+ } else {
+ println!("content-type: text/html\n");
+ println!("{}", reg.render("index", &String::new())?);
+ }
+ Ok(())
+ }() {
+ error!("{:#}", e);
+ println!("content-type: text/plain\n\n500");
+ }
}
-async fn shutdown_signal() {
- // Wait for CTRL+C
- tokio::signal::ctrl_c()
- .await
- .expect("failed to install CTRL+C signal handler");
+fn status() {
+ let vars = env::vars();
+ let mut input = String::new();
+
+ // begin writing
+ println!("Content-Type: text/html\n\n<html><body><ul>");
+
+ for each in vars {
+ println!("<li>{:?}</li>", &each);
+ }
+
+ println!("{:?}", &input);
}