feat: ✨ plays radio stream from url
feat: ✨ api structure
This commit is contained in:
parent
c908fdc097
commit
8f2b6f1e3f
17 changed files with 3534 additions and 0 deletions
13
back/Cargo.toml
Normal file
13
back/Cargo.toml
Normal file
|
@ -0,0 +1,13 @@
|
|||
[package]
|
||||
name = "back"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
axum = "0.7.4"
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.114"
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
tower-http = { version = "0.5.2", features = ["full"] }
|
6
back/src/lib.rs
Normal file
6
back/src/lib.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
pub mod routing;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppState{
|
||||
|
||||
}
|
23
back/src/main.rs
Normal file
23
back/src/main.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use back::{routing, AppState};
|
||||
use std::env::{self};
|
||||
|
||||
fn take_args() -> String{
|
||||
let mut bind_address:String = String::new();
|
||||
for element in env::args(){
|
||||
bind_address = element
|
||||
}
|
||||
println!("\n\n\tOn Air -> http://{}\n\n", bind_address);
|
||||
bind_address
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
let state = AppState{
|
||||
|
||||
};
|
||||
let app = routing::routing(axum::extract::State(state)).await;
|
||||
let listener = tokio::net::TcpListener::bind(take_args()).await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
20
back/src/routing.rs
Normal file
20
back/src/routing.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use crate::AppState;
|
||||
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
|
||||
pub async fn routing(State(state): State<AppState>) -> Router{
|
||||
Router::new()
|
||||
.route("/", get(alive))
|
||||
.layer(CorsLayer::permissive())
|
||||
.with_state(state.clone())
|
||||
}
|
||||
|
||||
async fn alive() -> impl IntoResponse{
|
||||
let alive_json = serde_json::json!({
|
||||
"status":"alive",
|
||||
});
|
||||
println!("Alive");
|
||||
(StatusCode::OK, Json(alive_json))
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue