diff options
author | 2024-11-13 20:00:15 +0000 | |
---|---|---|
committer | 2024-11-13 20:00:15 +0000 | |
commit | b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6 (patch) | |
tree | 280a31f5887aafdaa200a2b5f4c05ff106d9e365 /src/main.rs | |
download | critch-b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6.tar.gz critch-b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6.tar.bz2 critch-b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6.zip |
initial commit
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..639ba2d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,49 @@ +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 app = Route::new() + .at( + "/admin", + post(routes::admin::login).get(routes::admin::get_login_form), + ) + .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), + ) + .data(state); + + Server::new(TcpListener::bind("0.0.0.0:3000")) + .run(app) + .await?; + Ok(()) +} |