2019-06-30 01:25:33 +02:00
|
|
|
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;
|
2018-07-19 01:57:00 +02:00
|
|
|
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;
|
2019-06-30 01:25:33 +02:00
|
|
|
use actix::{SyncArbiter, 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 utils::{setup_logging, AppState, DbExecutor};
|
2018-06-06 03:32:40 +02:00
|
|
|
|
2019-05-07 01:14:51 +02:00
|
|
|
mod actions;
|
2019-03-24 21:17:55 +01: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");
|
2018-07-19 01:57:00 +02:00
|
|
|
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),
|
|
|
|
)
|
2018-07-19 01:57:00 +02:00
|
|
|
.get_matches();
|
|
|
|
|
|
|
|
let address = "127.0.0.1";
|
|
|
|
let port = "8888";
|
|
|
|
|
2019-04-25 00:37:29 +02:00
|
|
|
info!(log, "Loading configuration");
|
2018-07-19 01:57:00 +02:00
|
|
|
let config = matches.value_of("config").unwrap_or("");
|
|
|
|
if !config.is_empty() {
|
|
|
|
println!("Not implemented");
|
2019-04-25 00:37:29 +02:00
|
|
|
return;
|
2018-07-19 01:57:00 +02:00
|
|
|
}
|
|
|
|
|
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-06-30 01:25:33 +02:00
|
|
|
let app_data = web::Data::new(AppState {
|
|
|
|
log: setup_logging(),
|
|
|
|
db: addr.clone(),
|
|
|
|
});
|
|
|
|
|
2019-04-25 00:37:29 +02:00
|
|
|
info!(log, "Starting server");
|
2019-06-30 01:25:33 +02:00
|
|
|
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
|
|
|
}
|