diff --git a/backend/src/plugins/minecraft.rs b/backend/src/plugins/minecraft.rs index ccdacf3..09f4bc8 100644 --- a/backend/src/plugins/minecraft.rs +++ b/backend/src/plugins/minecraft.rs @@ -13,7 +13,7 @@ struct McData { static mut ACCESS_ADDRESS: String = String::new(); -pub fn register(app: &mut tide::Server, access_address: String) { +pub fn register(app: &mut tide::Server, access_address: String) -> Vec { println!("Enabling Minecraft plugin"); unsafe { @@ -21,6 +21,8 @@ pub fn register(app: &mut tide::Server, access_address: String) { } app.at("/api/minecraft").get(minecraft); + + vec![String::from("/api/minecraft")] } pub async fn minecraft(_req: tide::Request) -> Result { diff --git a/backend/src/plugins/mod.rs b/backend/src/plugins/mod.rs index 3e71dd4..5f8d43b 100644 --- a/backend/src/plugins/mod.rs +++ b/backend/src/plugins/mod.rs @@ -1,7 +1,16 @@ +use serde::Serialize; use crate::State; mod minecraft; +#[derive(Serialize, Clone)] +struct Plugin { + name: String, + endpoints: Vec, +} + +static mut PLUGINS: Vec = vec![]; + pub fn parse_enable_plugins(app: &mut tide::Server, plugins: Option, address: String) { if plugins.is_none() { return; @@ -14,11 +23,38 @@ pub fn parse_enable_plugins(app: &mut tide::Server, plugins: Option>(); + let mut registered_endpoints = vec![]; for plugin in plugins { - match plugin { + let endpoints = match plugin { "minecraft" => minecraft::register(app, address.clone()), - _ => {} + _ => {vec![]} + }; + + for endpoint in endpoints { + println!("Registered endpoint: {}", endpoint); + registered_endpoints.push(Plugin { + name: plugin.to_string(), + endpoints: vec![endpoint], + }); } } + + unsafe { + PLUGINS = registered_endpoints; + } + + app.at("/api/plugins").get(plugins_route); +} + +async fn plugins_route(_req: tide::Request) -> Result { + let mut res = tide::Response::new(200); + + unsafe { + res.set_body(serde_json::to_vec(&PLUGINS).unwrap()); + } + + res.set_content_type("application/json"); + + Ok(res) } \ No newline at end of file