A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
blob: e35aa185a53be2a454679e34051a8b56b59e6b13 (1539 bytes)[doc][blame][raw]
1
use sqlx::postgres::Postgres;2
use tide_compress::CompressMiddleware;3
use tide_sqlx::SQLxMiddleware;5
use crate::abort;6
use crate::middleware::Auth;7
use crate::middleware::Cors;8
use crate::middleware::Error;9
use crate::route;10
use crate::Config;11
use crate::Result;13
#[derive(Default)]14
pub struct Server;16
impl Server {17
pub async fn run(&self) -> Result<()> {18
let config = Config::acquire().unwrap_or_else(|err| abort(&err));19
let mut app = tide::new();21
/* bind middleware */22
app.with(Error::default());23
app.with(24
SQLxMiddleware::<Postgres>::new(&config.database.to_string())25
.await26
.unwrap(),27
);28
app.with(Auth::default());29
app.with(Cors::new(&config.server.options.origin));30
app.with(CompressMiddleware::new());32
/* serve content */33
app.at("/").serve_file("www/index.html")?;34
app.at("/asset").serve_dir("www/asset/")?;35
app.at("/app").serve_dir("app/")?;37
/* handle prefetch */38
app.at("*").options(route::do_prefetch);40
/* handle api requests */41
app.at("/api/account").get(route::get_account);42
app.at("/api/search").get(route::do_search);43
app.at("/api/song").get(route::get_song);44
app.at("/api/favorite").get(route::get_favorites);45
app.at("/api/favorite").post(route::add_favorite);46
app.at("/api/favorite").delete(route::delete_favorite);48
app.listen(&config.server.to_string()).await?;49
Ok(())50
}51
}