This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
generated from TrueDoctor/DiscoBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
077f5a0
commit 4212e4e
Showing
2 changed files
with
17 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |