so://phie

verbal

A mobile app for listening to radio stations from around the globe
git clone git://soophie.de/verbal

blob: 2c5d2cd3483e5fa32aea476c04ef2b872e3e9d6c (2104 bytes)[doc][blame][raw]

1#[macro_use]

2extern crate diesel;

3

4use tide_compress::CompressMiddleware;

5use tide_diesel::DieselMiddleware;

6

7mod api;

8mod config;

9mod data;

10mod error;

11mod middleware;

12mod model;

13mod response;

14mod rest;

15mod schema;

16mod service;

17mod utils;

18

19use api::Search;

20use config::Config;

21use error::ErrorKind;

22use middleware::{AuthMiddleware, CorsMiddleware};

23use response::Response;

24use service::Service;

25

26#[async_std::main]

27async fn main() -> tide::Result<()> {

28 let config = Config::from_file("./config.ron").expect("Unable to parse config!");

29

30 let mut app = tide::new();

31

32 /* bind database middleware */

33 app.with(DieselMiddleware::new(&config.database.to_string()).unwrap());

34

35 /* bind cors middleware */

36 app.with(CorsMiddleware::new(&config.options.origin));

37

38 /* bind auth middleware */

39 app.with(AuthMiddleware::new());

40

41 /* bind compression middleware */

42 app.with(CompressMiddleware::new());

43

44 /* handle prefetch */

45 app.at("*")

46 .options(|_: tide::Request<()>| async move { Ok(tide::Response::new(200)) });

47

48 /* provide index */

49 app.at("/").serve_file("www/index.html")?;

50

51 /* provide assets */

52 app.at("/asset").serve_dir("www/asset/")?;

53

54 /* provide app */

55 app.at("/app").serve_dir("app/")?;

56

57 app.at("/api/search")

58 .get(|req: tide::Request<()>| async move {

59 let search = match req.query::<Search>() {

60 Ok(query) => query,

61 Err(err) => return Response::throw(ErrorKind::Arguments, &err.to_string()),

62 };

63 match Service::search(search, req).await {

64 Ok(data) => Response::with(data),

65 Err(err) => Response::throw(ErrorKind::Fetch, &err.to_string()),

66 }

67 });

68

69 app.at("/api/favorite")

70 .get(|req: tide::Request<()>| async move {

71 match Service::get_favorites(req).await {

72 Ok(data) => Response::with(data),

73 Err(err) => Response::throw(ErrorKind::Fetch, &err.to_string()),

74 }

75 });

76

77 app.listen(&config.server.to_string()).await?;

78

79 Ok(())

80}