Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Restructure main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueDoctor committed Aug 2, 2020
1 parent 077f5a0 commit 4212e4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 16 additions & 70 deletions lobby/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<GameType>,
games: Vec<Game>,
}

// routes are here for now :)
#[get("/")]
fn index() -> &'static str {
"Hello, rask!"
}

#[get("/api/lobby", format="json")]
fn gameIndex() -> Json<GameOverview> {
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();
}

0 comments on commit 4212e4e

Please sign in to comment.