blob: a48883595084e21ab1d6f90397e1fa9df35f0b33 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
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
}
|