rusty-hub/src/main.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2018-06-06 03:32:40 +02:00
extern crate actix_web;
2019-03-31 20:14:56 +02:00
extern crate askama;
extern crate clap;
2019-04-25 00:37:29 +02:00
#[macro_use]
extern crate slog;
extern crate slog_async;
extern crate slog_term;
use actix_web::{http, server, App};
use clap::Arg;
use controllers::{hub, index};
use utils::{setup_logging, AppState};
2018-06-06 03:32:40 +02:00
mod controllers;
2019-04-25 00:37:29 +02:00
mod utils;
2018-06-06 03:32:40 +02:00
2018-06-05 02:22:33 +02:00
fn main() {
2019-04-25 00:37:29 +02:00
let log = setup_logging();
info!(log, "Launching hub");
let matches = clap::App::new("Rusty Hub")
.version("0.1.0")
.author("Gonçalo Valério <gon@ovalerio.net>")
.about("Runs a simple and compliant websub hub")
2019-04-25 00:37:29 +02:00
.arg(
Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Sets a custom config file")
.takes_value(true),
)
.get_matches();
let address = "127.0.0.1";
let port = "8888";
2019-04-25 00:37:29 +02:00
info!(log, "Loading configuration");
let config = matches.value_of("config").unwrap_or("");
if !config.is_empty() {
println!("Not implemented");
2019-04-25 00:37:29 +02:00
return;
}
2019-04-25 00:37:29 +02:00
info!(log, "Starting server");
server::new(move || {
App::with_state(AppState {
log: setup_logging(),
})
2019-03-31 20:14:56 +02:00
.route("/", http::Method::GET, index)
2019-04-25 00:37:29 +02:00
.route("/", http::Method::POST, hub)
})
.bind(format!("{}:{}", address, port))
.unwrap()
.run();
info!(log, "Shutting down server");
2018-06-05 02:22:33 +02:00
}