blob: a48883595084e21ab1d6f90397e1fa9df35f0b33 (
plain) (
tree)
|
|
use actix_session::storage::CookieSessionStore;
use actix_session::SessionMiddleware;
use actix_web::cookie::Key;
use actix_web::http::StatusCode;
use actix_web::middleware::ErrorHandlers;
use actix_web::{web, App, HttpServer};
use sqlx::postgres::PgPoolOptions;
use pinussy::db::Database;
use pinussy::routes;
use pinussy::Pinussy;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let pool = PgPoolOptions::new()
.max_connections(5)
.connect("postgres://pinussy:pinussy@localhost/pinussy")
.await
.unwrap();
sqlx::migrate!("./migrations").run(&pool).await.unwrap();
let pinussy = Pinussy {
db: Database::new(pool),
};
HttpServer::new(move || {
App::new()
.wrap(SessionMiddleware::new(
// TODO: postgres session store
CookieSessionStore::default(),
Key::generate(),
))
.wrap(
ErrorHandlers::new()
.handler(StatusCode::NOT_FOUND, routes::error::render_404)
.handler(StatusCode::INTERNAL_SERVER_ERROR, routes::error::render_500),
)
.app_data(web::Data::new(pinussy.clone()))
.service(web::resource("/static/{filename}").to(routes::r#static::file))
.service(routes::home::get)
// .service(home_auth)
.service(routes::login::get)
.service(routes::login::post)
.service(routes::logout::post)
.service(routes::signup::get)
.service(routes::signup::post)
.service(routes::users::get)
// .service(get_pins)
// .service(post_pin)
// .service(get_pin)
// .service(post_board)
// .service(get_board)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}
|