diff --git a/Cargo.lock b/Cargo.lock index 1f7da908..a7acfc32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2324,7 +2324,7 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wee_alloc" version = "0.4.5" -source = "git+https://github.com/zshipko/wee_alloc/?branch=master#ea7c2b88664ad61765ba98b24c18828527ec7c6e" +source = "git+https://github.com/zshipko/wee_alloc/#ea7c2b88664ad61765ba98b24c18828527ec7c6e" dependencies = [ "cfg-if", "libc", diff --git a/lobby/src/main.rs b/lobby/src/main.rs index 82d57caa..14341c21 100644 --- a/lobby/src/main.rs +++ b/lobby/src/main.rs @@ -1,76 +1,22 @@ -#![feature(proc_macro_hygiene, decl_macro)] - -use std::vec::Vec; - -#[macro_use] extern crate rocket; -#[macro_use] extern crate serde_derive; +#![feature(decl_macro)] +#![feature(proc_macro_hygiene)] +use lobby::routes::*; use rocket::fairing::AdHoc; use rocket::http::Header; -use rocket_contrib::json::Json; - -use serde::Serialize; - -// this is just here for a POC. -// TODO move those into their own file -#[derive(Debug, Serialize)] -struct GameType { - name: String, - icon: String, - displayName: String, -} - -#[derive(Debug, Serialize)] -struct Game { - name: String, - type_: String, - id: u8, - maxUsers: u8, - userCount: u8, - hasPassword: bool, -} - -#[derive(Debug, Serialize)] -struct GameOverview { - gameTypes: Vec, - games: Vec, -} - -// routes are here for now :) -#[get("/")] -fn index() -> &'static str { - "Hello, rask!" -} - -#[get("/api/lobby", format="json")] -fn gameIndex() -> Json { - let mock_data = GameOverview { - gameTypes: vec![ - (GameType { - name: "rask".to_string(), - icon: "./resources/icon_rask.png".to_string(), - displayName: "Rask".to_string() - }) - ], - games: vec![ - (Game { - name: "Rask".to_string(), - type_: "rask".to_string(), - id: 1, - maxUsers: 5, - userCount: 0, - hasPassword: true, - }) - ] - }; - Json(mock_data) +pub fn rocket() -> rocket::Rocket { + let routes = rocket::routes![index, game_index, token_request]; + rocket::ignite() + .mount("/", routes) + .attach(AdHoc::on_response( + "CORS header for dev env", + |_req, res| { + #[cfg(debug_assertions)] + res.set_header(Header::new("Access-Control-Allow-Origin", "*")); + }, + )) } -fn main() { - rocket::ignite().mount("/", routes![index, gameIndex]) - .attach(AdHoc::on_response("CORS header for dev env", |req, res| { - #[cfg(debug_assertions)] - res.set_header(Header::new("Access-Control-Allow-Origin", "*")); - })) - .launch(); +pub fn main() { + rocket().launch(); }