A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal
4
edition = "2018"6
[dependencies]7
ron = "*"7
toml = "*"8
tide = "*"9
rand = "*"10
surf = "*"
6
pub struct Server {7
pub hostname: String,8
pub port: i32,9
pub options: Options,10
}12
impl fmt::Display for Server {
16
}18
#[derive(Debug, Clone, Deserialize)]19
pub struct Options {20
pub origin: String,21
}23
#[derive(Debug, Clone, Deserialize)]24
pub struct Database {25
pub hostname: String,26
pub port: i32,
40
}42
#[derive(Debug, Clone, Deserialize)]37
pub struct Options {38
pub origin: String,39
}41
#[derive(Debug, Clone, Deserialize)]43
pub struct Config {44
pub server: Server,45
pub database: Database,45
pub options: Options,46
}48
impl Config {49
pub fn from_file(path: &str) -> Result<Self, ron::Error> {49
pub fn from_file(path: &str) -> Result<Self, toml::de::Error> {50
let raw = fs::read_to_string(path).expect("Unable to locate config.ron file!");51
ron::from_str(&raw)51
toml::from_str(&raw)52
}53
}
23
#[async_std::main]24
async fn main() -> tide::Result<()> {25
let config = Config::from_file("./config.ron").expect("Unable to parse config!");25
let config = Config::from_file("./config.toml").expect("Unable to parse config!");27
let mut app = tide::new();
34
);36
/* bind cors middleware */37
app.with(CorsMiddleware::new(&config.options.origin));37
app.with(CorsMiddleware::new(&config.server.options.origin));39
/* bind auth middleware */40
app.with(AuthMiddleware::new());