blob: 9d6ec4f077f48cb8e9753fa312542f4d4944467b (
plain)
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
|
mod routes;
mod structs;
use actix_web::{web, App, HttpServer};
use dotenv::dotenv;
use sqlx::mysql::{MySqlPool, MySqlPoolOptions};
use std::env;
#[derive(Clone)]
struct AppState {
pool: MySqlPool,
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
let pool: MySqlPool = MySqlPoolOptions::new()
.max_connections(10)
.connect(
env::var("DATABASE_URL")
.expect("environment variables are *probably not setted up!!")
.as_str(),
)
.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::song::song)
})
.bind(("127.0.0.1", 8000))?
.run()
.await
}
async fn root() -> String {
String::from("Server is up and running")
}
|