2018-12-09 16:55:36 +01:00
|
|
|
// to avoid the warning from diesel macros
|
|
|
|
#![allow(proc_macro_derive_resolution_fallback)]
|
|
|
|
|
|
|
|
extern crate actix;
|
|
|
|
extern crate actix_web;
|
2019-03-10 03:03:09 +01:00
|
|
|
extern crate bcrypt;
|
2018-12-09 16:55:36 +01:00
|
|
|
extern crate chrono;
|
|
|
|
extern crate dotenv;
|
2019-03-10 03:03:09 +01:00
|
|
|
extern crate env_logger;
|
2018-12-09 16:55:36 +01:00
|
|
|
extern crate futures;
|
|
|
|
extern crate jsonwebtoken as jwt;
|
2019-03-10 03:03:09 +01:00
|
|
|
extern crate r2d2;
|
|
|
|
extern crate serde;
|
2018-12-09 16:55:36 +01:00
|
|
|
extern crate sparkpost;
|
2019-03-10 03:03:09 +01:00
|
|
|
extern crate uuid;
|
2018-12-09 16:55:36 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate failure;
|
|
|
|
|
|
|
|
mod app;
|
|
|
|
mod auth_handler;
|
|
|
|
mod auth_routes;
|
2019-03-10 03:03:09 +01:00
|
|
|
mod email_service;
|
|
|
|
mod errors;
|
2018-12-09 16:55:36 +01:00
|
|
|
mod invitation_handler;
|
|
|
|
mod invitation_routes;
|
2019-03-10 03:03:09 +01:00
|
|
|
mod models;
|
2018-12-09 16:55:36 +01:00
|
|
|
mod register_handler;
|
|
|
|
mod register_routes;
|
2019-03-10 03:03:09 +01:00
|
|
|
mod schema;
|
2018-12-09 16:55:36 +01:00
|
|
|
mod utils;
|
|
|
|
|
|
|
|
use actix::prelude::*;
|
|
|
|
use actix_web::server;
|
|
|
|
use diesel::{r2d2::ConnectionManager, PgConnection};
|
|
|
|
use dotenv::dotenv;
|
2019-03-10 03:03:09 +01:00
|
|
|
use models::DbExecutor;
|
2018-12-09 16:55:36 +01:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
dotenv().ok();
|
|
|
|
std::env::set_var("RUST_LOG", "simple-auth-server=debug,actix_web=info");
|
|
|
|
std::env::set_var("RUST_BACKTRACE", "1");
|
|
|
|
env_logger::init();
|
|
|
|
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
|
|
|
|
let sys = actix::System::new("Actix_Tutorial");
|
|
|
|
|
|
|
|
// create db connection pool
|
|
|
|
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
|
|
|
let pool = r2d2::Pool::builder()
|
|
|
|
.build(manager)
|
|
|
|
.expect("Failed to create pool.");
|
|
|
|
|
2019-03-10 03:03:09 +01:00
|
|
|
let address: Addr<DbExecutor> =
|
|
|
|
SyncArbiter::start(4, move || DbExecutor(pool.clone()));
|
2018-12-09 16:55:36 +01:00
|
|
|
|
|
|
|
server::new(move || app::create_app(address.clone()))
|
|
|
|
.bind("127.0.0.1:3000")
|
|
|
|
.expect("Can not bind to '127.0.0.1:3000'")
|
|
|
|
.start();
|
|
|
|
|
|
|
|
sys.run();
|
|
|
|
}
|