update code to work with actix-web 2.0
This commit is contained in:
parent
a143046597
commit
3ea874c962
File diff suppressed because it is too large
Load Diff
|
@ -2,10 +2,12 @@
|
|||
name = "rusty-hub"
|
||||
version = "0.1.0"
|
||||
authors = ["Gonçalo Valério <gon@ovalerio.net>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.8.3"
|
||||
actix-web = "1.0.2"
|
||||
actix-rt = "1.0"
|
||||
actix-web = "2.0"
|
||||
r2d2 = "0.8.5"
|
||||
diesel = { version = "1.4.2", features = ["sqlite", "r2d2"] }
|
||||
toml = "0.5.0"
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use super::schema::subscriptions;
|
||||
use super::schema::subscriptions::dsl::*;
|
||||
use crate::models::*;
|
||||
use crate::utils::{setup_logging, Pool};
|
||||
use diesel::prelude::*;
|
||||
use models::*;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use utils::{setup_logging, Pool};
|
||||
|
||||
pub fn handle_subscription(db: &Pool, data: &HashMap<String, String>) -> bool {
|
||||
let log = setup_logging();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use actions::{handle_publication, handle_subscription};
|
||||
use crate::actions::{handle_publication, handle_subscription};
|
||||
use crate::utils::{validate_parsed_data, AppState};
|
||||
use actix_web::{http, web, HttpRequest, HttpResponse};
|
||||
use askama::Template;
|
||||
use std::collections::HashMap;
|
||||
use url::form_urlencoded;
|
||||
use utils::{validate_parsed_data, AppState};
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "index.html")]
|
||||
|
@ -49,11 +49,11 @@ pub fn hub(state: web::Data<AppState>, _req: HttpRequest, params: String) -> Htt
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::utils::setup_logging;
|
||||
use actix::System;
|
||||
use actix_web::{http, test, web};
|
||||
use diesel::prelude::*;
|
||||
use diesel::r2d2::{self, ConnectionManager};
|
||||
use utils::setup_logging;
|
||||
|
||||
#[test]
|
||||
fn test_index() {
|
||||
|
|
25
src/main.rs
25
src/main.rs
|
@ -1,20 +1,13 @@
|
|||
extern crate actix;
|
||||
extern crate actix_web;
|
||||
extern crate askama;
|
||||
extern crate clap;
|
||||
#[macro_use]
|
||||
extern crate diesel;
|
||||
#[macro_use]
|
||||
extern crate slog;
|
||||
extern crate slog_async;
|
||||
extern crate slog_term;
|
||||
extern crate url;
|
||||
use actix::System;
|
||||
use actix_web::{web, App, HttpServer};
|
||||
use clap::Arg;
|
||||
use controllers::{hub, index};
|
||||
use diesel::prelude::*;
|
||||
use diesel::r2d2::{self, ConnectionManager};
|
||||
use std::io::{Error, ErrorKind};
|
||||
use utils::{setup_logging, AppState};
|
||||
|
||||
mod actions;
|
||||
|
@ -23,7 +16,8 @@ mod models;
|
|||
mod schema;
|
||||
mod utils;
|
||||
|
||||
fn main() {
|
||||
#[actix_rt::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let matches = clap::App::new("Rusty Hub")
|
||||
.version("0.1.0")
|
||||
.author("Gonçalo Valério <gon@ovalerio.net>")
|
||||
|
@ -49,10 +43,9 @@ fn main() {
|
|||
let config = matches.value_of("config").unwrap_or("");
|
||||
if !config.is_empty() {
|
||||
error!(log, "Configuration not implemented yet");
|
||||
return;
|
||||
return Err(Error::new(ErrorKind::Other, "no_config"));
|
||||
}
|
||||
|
||||
let sys = System::new("rusty-hub");
|
||||
let manager = ConnectionManager::<SqliteConnection>::new(storage);
|
||||
let pool = r2d2::Pool::builder()
|
||||
.build(manager)
|
||||
|
@ -66,13 +59,11 @@ fn main() {
|
|||
info!(log, "Starting server");
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.register_data(app_data.clone())
|
||||
.app_data(app_data.clone())
|
||||
.route("/", web::get().to(index))
|
||||
.route("/", web::post().to(hub))
|
||||
})
|
||||
.bind(format!("{}:{}", address, port))
|
||||
.unwrap()
|
||||
.start();
|
||||
let _ = sys.run();
|
||||
info!(log, "Shutting down server");
|
||||
.bind(format!("{}:{}", address, port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue