rusty-hub/src/main.rs

69 lines
1.7 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]
2019-04-25 23:52:17 +02:00
extern crate diesel;
#[macro_use]
2019-04-25 00:37:29 +02:00
extern crate slog;
extern crate slog_async;
extern crate slog_term;
2019-04-25 23:52:17 +02:00
use actix_web::actix::{SyncArbiter, System};
2019-04-25 00:37:29 +02:00
use actix_web::{http, server, App};
use clap::Arg;
use controllers::{hub, index};
2019-04-25 23:52:17 +02:00
use diesel::prelude::*;
use utils::{setup_logging, AppState, DbExecutor};
2018-06-06 03:32:40 +02:00
mod controllers;
2019-04-25 23:52:17 +02:00
mod models;
mod schema;
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 23:52:17 +02:00
let sys = System::new("rusty-hub");
let addr = SyncArbiter::start(3, || {
DbExecutor(SqliteConnection::establish("local.db").unwrap())
});
2019-04-25 00:37:29 +02:00
info!(log, "Starting server");
server::new(move || {
App::with_state(AppState {
log: setup_logging(),
2019-04-25 23:52:17 +02:00
db: addr.clone(),
2019-04-25 00:37:29 +02:00
})
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()
2019-04-25 23:52:17 +02:00
.start();
let _ = sys.run();
2019-04-25 00:37:29 +02:00
info!(log, "Shutting down server");
2018-06-05 02:22:33 +02:00
}