2020-03-27 12:17:27 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate diesel;
|
2020-04-03 14:29:30 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2020-03-27 12:17:27 +01:00
|
|
|
|
|
|
|
use actix_cors::Cors;
|
|
|
|
use actix_web::{web, App, HttpServer};
|
|
|
|
|
|
|
|
pub mod db;
|
2020-03-27 16:17:25 +01:00
|
|
|
pub mod errors;
|
2020-03-27 12:17:27 +01:00
|
|
|
pub mod middleware;
|
|
|
|
pub mod models;
|
|
|
|
pub mod routes;
|
|
|
|
pub mod schema;
|
|
|
|
|
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> Result<(), String> {
|
|
|
|
dotenv::dotenv().ok();
|
2020-04-03 14:29:30 +02:00
|
|
|
pretty_env_logger::init();
|
2020-03-27 12:17:27 +01:00
|
|
|
|
2020-03-30 14:26:25 +02:00
|
|
|
let port = std::env::var("JIRS_SERVER_PORT").unwrap_or_else(|_| "3000".to_string());
|
|
|
|
let bind = std::env::var("JIRS_SERVER_BIND").unwrap_or_else(|_| "0.0.0.0".to_string());
|
|
|
|
let addr = format!("{}:{}", bind, port);
|
|
|
|
|
2020-03-27 12:17:27 +01:00
|
|
|
let db_addr = actix::SyncArbiter::start(4, || crate::db::DbExecutor::new());
|
|
|
|
|
|
|
|
HttpServer::new(move || {
|
|
|
|
App::new()
|
|
|
|
.wrap(actix_web::middleware::Logger::default())
|
|
|
|
.wrap(Cors::default())
|
|
|
|
.data(db_addr.clone())
|
2020-03-27 16:17:25 +01:00
|
|
|
.data(crate::db::build_pool())
|
2020-03-27 12:17:27 +01:00
|
|
|
.service(
|
|
|
|
web::scope("/issues")
|
|
|
|
.service(crate::routes::issues::project_issues)
|
2020-03-28 21:41:16 +01:00
|
|
|
.service(crate::routes::issues::issue_with_users_and_comments)
|
2020-03-27 12:17:27 +01:00
|
|
|
.service(crate::routes::issues::create)
|
|
|
|
.service(crate::routes::issues::update)
|
|
|
|
.service(crate::routes::issues::delete),
|
|
|
|
)
|
|
|
|
.service(
|
|
|
|
web::scope("/comments")
|
|
|
|
.service(crate::routes::comments::create)
|
|
|
|
.service(crate::routes::comments::update)
|
|
|
|
.service(crate::routes::comments::delete),
|
|
|
|
)
|
2020-03-29 19:56:55 +02:00
|
|
|
.service(web::scope("/currentUser").service(crate::routes::users::current_user))
|
2020-03-27 16:17:25 +01:00
|
|
|
.service(
|
|
|
|
web::scope("/project")
|
|
|
|
.service(crate::routes::projects::project_with_users_and_issues)
|
|
|
|
.service(crate::routes::projects::update),
|
|
|
|
)
|
2020-03-27 12:17:27 +01:00
|
|
|
})
|
2020-03-30 14:26:25 +02:00
|
|
|
.bind(addr)
|
2020-03-27 12:17:27 +01:00
|
|
|
.map_err(|e| format!("{}", e))?
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.expect("Server internal error");
|
|
|
|
Ok(())
|
|
|
|
}
|