summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
author53hornet <atc@53hor.net>2022-01-22 08:45:24 -0500
committerAdam T. Carpenter <atc@53hor.net>2022-01-22 15:18:04 -0500
commitba49aa806a48839b61fb261f7ccd007a507d8d50 (patch)
tree222855376c301972a10bb8656c94731fc40ded76 /src/main.rs
parentd7472320a00fa0bfd6b9be904e0730461f093f61 (diff)
downloadtwinh-ba49aa806a48839b61fb261f7ccd007a507d8d50.tar.xz
twinh-ba49aa806a48839b61fb261f7ccd007a507d8d50.zip
feat: experimental cgi forkcgi
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);
}