2019-04-30 07:53:13 +00:00
|
|
|
extern crate actix_web;
|
2019-05-01 02:49:22 +00:00
|
|
|
extern crate env_logger;
|
2019-04-30 07:53:13 +00:00
|
|
|
extern crate reqwest;
|
|
|
|
extern crate ron;
|
|
|
|
extern crate serde;
|
2019-05-01 02:49:22 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate tera;
|
2019-04-30 07:53:13 +00:00
|
|
|
|
2019-05-01 05:28:57 +00:00
|
|
|
mod config;
|
2019-05-01 05:41:52 +00:00
|
|
|
mod handlers;
|
2019-05-01 02:49:22 +00:00
|
|
|
mod utils;
|
|
|
|
|
2019-05-01 05:28:57 +00:00
|
|
|
use self::config::*;
|
2019-05-01 05:41:52 +00:00
|
|
|
use self::handlers::*;
|
|
|
|
use actix_web::{middleware::Logger, web::resource, App, HttpServer};
|
2019-04-30 05:44:26 +00:00
|
|
|
use ron::de::from_str;
|
2019-05-01 06:15:20 +00:00
|
|
|
use std::{error::Error, fs::read_to_string};
|
2019-04-30 08:20:01 +00:00
|
|
|
|
2019-04-30 05:44:26 +00:00
|
|
|
fn main() -> Result<(), Box<Error>> {
|
|
|
|
let config = from_str::<Config>(&read_to_string("./endstat_conf.ron")?)?;
|
2019-05-01 02:49:22 +00:00
|
|
|
let bind_addr = config.bind_address.clone();
|
|
|
|
std::env::set_var("RUST_LOG", "actix_web=info");
|
|
|
|
env_logger::init();
|
2019-04-30 06:47:35 +00:00
|
|
|
|
2019-05-01 02:49:22 +00:00
|
|
|
HttpServer::new(move || {
|
|
|
|
let tera = compile_templates!(concat!(env!("CARGO_MANIFEST_DIR"), "/templates/**/*"));
|
|
|
|
|
|
|
|
App::new()
|
2019-05-01 06:15:20 +00:00
|
|
|
.data(State::new(&config))
|
2019-05-01 02:49:22 +00:00
|
|
|
.data(tera)
|
|
|
|
.wrap(Logger::default())
|
|
|
|
.service(resource("/").to(index))
|
|
|
|
.service(resource("/api").to(json_endpoint))
|
2019-04-30 07:53:13 +00:00
|
|
|
})
|
2019-05-01 02:49:22 +00:00
|
|
|
.bind(&bind_addr)?
|
|
|
|
.run()?;
|
2019-04-30 06:47:35 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|