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 poem::session::{CookieConfig, CookieSession};
use poem::web::cookie::CookieKey;
use poem::{delete, post, put, EndpointExt};
use poem::{get, listener::TcpListener, Route, Server};
use critch::config::Config;
use critch::routes;
use critch::Critch;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let config = Config::from_file("./critch.toml").unwrap();
let state = Critch::new(config).await;
let cookie_config = CookieConfig::private(CookieKey::generate());
let cookie_session = CookieSession::new(cookie_config);
let app = Route::new()
.at("/admin", get(routes::admin::get_dashboard))
.at(
"/admin/login",
post(routes::admin::login).get(routes::admin::get_login_form),
)
.at("/admin/logout", post(routes::admin::logout))
.at("/", get(routes::artworks::get))
.at(
"/artworks",
get(routes::artworks::get).post(routes::artworks::post),
)
.at(
"/artworks/:artwork",
get(routes::artworks::get)
.put(routes::artworks::put)
.delete(routes::artworks::delete),
)
.at(
"/artists",
get(routes::artists::get).post(routes::artists::post),
)
.at(
"/artists/:artist",
get(routes::artists::get)
.put(routes::artists::put)
.delete(routes::artists::delete),
)
.at(
"/artworks/:artwork/comments",
post(routes::artworks::comments::post).delete(routes::artworks::comments::delete),
)
.catch_all_error(routes::error::error)
.data(state)
.with(cookie_session);
Server::new(TcpListener::bind("0.0.0.0:3000"))
.run(app)
.await?;
Ok(())
}
|