rusty-hub/src/main.rs

77 lines
1.9 KiB
Rust
Raw Normal View History

extern crate actix;
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-05-07 01:14:51 +02:00
extern crate url;
use actix::{System};
use actix_web::{web, App, HttpServer};
2019-04-25 00:37:29 +02:00
use clap::Arg;
use controllers::{hub, index};
2019-04-25 23:52:17 +02:00
use diesel::prelude::*;
use diesel::r2d2::{self, ConnectionManager};
use utils::{setup_logging, AppState};
2018-06-06 03:32:40 +02:00
2019-05-07 01:14:51 +02:00
mod actions;
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 manager = ConnectionManager::<SqliteConnection>::new("local.db");
let pool = r2d2::Pool::builder()
.build(manager)
.expect("Failed to create pool.");
2019-04-25 23:52:17 +02:00
let app_data = web::Data::new(AppState {
log: setup_logging(),
db: pool.clone(),
});
2019-04-25 00:37:29 +02:00
info!(log, "Starting server");
HttpServer::new(move || {
App::new()
.register_data(app_data.clone())
.route("/", web::get().to(index))
.route("/", web::post().to(hub))
2019-04-25 00:37:29 +02:00
})
.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
}