use actix_web::{web, App, HttpServer, middleware};
use sqlx::postgres::PgPoolOptions;
use log::{info, debug};
use my_app::{
utils::logger,
account,
};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
logger::setup_logger();
info!("서버 시작 준비");
debug!("데이터베이스 연결 시도");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect("postgres://user:password@db:5432/mydatabase")
.await
.expect("Failed to create pool");
info!("데이터베이스 연결 성공");
debug!("데이터베이스 마이그레이션 시작");
sqlx::migrate!("./migrations")
.run(&pool)
.await
.expect("Failed to migrate database");
info!("데이터베이스 마이그레이션 완료");
info!("Starting server at http://localhost:8080");
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(pool.clone()))
.wrap(middleware::Logger::default())
.wrap(middleware::Compress::default())
.configure(account::init_routes) })
.bind("0.0.0.0:8080")?
.run()
.await
}