blob: f1a58ec80aae088e904ab0f85c47bb3213c8825e (
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
|
mod routes;
mod structs;
mod database;
use actix_web::{web, App, HttpServer};
use dotenv::dotenv;
use std::sync::Arc;
struct AppState {
database: database::DatabaseWrapper
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenv().ok();
let app_state_raw = database::DatabaseWrapper::new().await.expect("Something went wrong -- DatabaseWrapper::new()");
let app_state = Arc::new(app_state_raw);
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(Arc::clone(&app_state)))
.route("/", web::get().to(root))
.service(routes::song::song)
.service(routes::album::album)
.service(routes::artist::artist)
})
.bind(("127.0.0.1", 8000))?
.run()
.await
}
async fn root() -> String {
String::from("Server is up and running")
}
|