diff options
author | nil <nil@tfwhyno.gf> | 2024-10-02 17:48:56 +0200 |
---|---|---|
committer | nil <nil@tfwhyno.gf> | 2024-10-02 17:48:56 +0200 |
commit | 0972fa6eab8c9111311f082ba8abfdc6b4a40945 (patch) | |
tree | 4eedbdc1a7cfdeee9d651c9871a9f26ab6da56d4 /src/main.rs | |
parent | 012c2c03b29a987ca4eead023ded22e01aa7477b (diff) |
commit changes
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..af45779 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,35 @@ +mod structs; +mod routes; + +use actix_web::{web, App, HttpServer}; +use sqlx::mysql::{MySqlPool, MySqlPoolOptions}; + +#[derive(Clone)] +struct AppState { + pool: MySqlPool, +} + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + let pool: MySqlPool = MySqlPoolOptions::new() + .max_connections(10) + .connect(DB_URL) + .await + .unwrap(); + + let app_state = AppState { pool }; + + HttpServer::new(move || { + App::new() + .app_data(web::Data::new(app_state.clone())) + .route("/", web::get().to(root)) + .service(routes::hello::hello_actix) + }) + .bind(("127.0.0.1", 8000))? + .run() + .await +} + +async fn root() -> String { + String::from("Server is up and running") +} |