summaryrefslogblamecommitdiff
path: root/src/main.rs
blob: edf8be17f0ebf06f6b61c7aa21a597dabe218a26 (plain) (tree)
1
2
3
4
5
6
7
8



                        

           

              























                                                                 

 











                                                            
 
use anyhow::Result;
use log::{debug, error};
use std::env;
use std::io::prelude::*;

mod config;
mod templates;

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");
    }
}

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);
}