|
|
@@ -1,9 +1,16 @@
|
|
|
-use actix_web::{HttpServer, web, App};
|
|
|
+use actix_web::{HttpServer, web, middleware, App};
|
|
|
use actix_cors::Cors;
|
|
|
+use sqlx::PgPool;
|
|
|
+use crate::app_error::AppError;
|
|
|
+
|
|
|
+mod app_error;
|
|
|
+mod routes;
|
|
|
+mod controllers;
|
|
|
|
|
|
#[actix_web::main]
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
let app_env = std::env::var("APP_ENV").unwrap_or_else(|_| "development".to_string());
|
|
|
+ let pool = PgPool::connect("postgres://leemorgan@localhost:5432/homo").await?;
|
|
|
|
|
|
HttpServer::new(move || {
|
|
|
let cors = if app_env == "development" {
|
|
|
@@ -19,13 +26,15 @@ async fn main() -> std::io::Result<()> {
|
|
|
};
|
|
|
|
|
|
App::new()
|
|
|
+ .wrap(middleware::Compress::default())
|
|
|
.wrap(cors)
|
|
|
+ .app_data(web::Data::new(pool))
|
|
|
.app_data(
|
|
|
web::JsonConfig::default().error_handler(|err, _req| {
|
|
|
AppError::JsonDeserializationError(err.to_string()).into()
|
|
|
})
|
|
|
)
|
|
|
- .configure(routes::other::config)
|
|
|
+ .configure(routes::user::config)
|
|
|
})
|
|
|
.bind(("0.0.0.0", 8000))?
|
|
|
.run()
|