diff --git a/server-api/.env b/server-api/.env index 29fe3e0..1f3d283 100644 --- a/server-api/.env +++ b/server-api/.env @@ -4,4 +4,11 @@ DATABASE_PASS=password DATABASE_USER=freechat_dev DATABASE_HOST=localhost DATABASE_PORT=3306 -REDIS_URL=redis://127.0.0.1:6379 \ No newline at end of file +REDIS_URL=redis://127.0.0.1:6379 + + +# Server meta things +SERVER_NAME="Freechat Dev Server" +SERVER_DESCRIPTION="Server for sick development things" +SERVER_URL=localhost +SERVER_PORT=8888 \ No newline at end of file diff --git a/server-api/client-tests/client.py b/server-api/client-tests/client.py index 147103d..d23e6f2 100644 --- a/server-api/client-tests/client.py +++ b/server-api/client-tests/client.py @@ -173,7 +173,8 @@ def auth_tests(worker): # fail 400 worker.post('/channels/create', jwt=False, name=f'succ', kind=2) - # fail + # pass 200 + worker.get('/meta', jwt=jwt) if __name__ == '__main__': worker = Test(create_admin=False, init_verbose=True) diff --git a/server-api/src/main.rs b/server-api/src/main.rs index 41e65cf..ea4c3a9 100644 --- a/server-api/src/main.rs +++ b/server-api/src/main.rs @@ -30,6 +30,7 @@ use auth::AuthReason; mod auth; mod routes; +mod meta; mod invites; mod channels; mod members; @@ -65,6 +66,8 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response, meth: &Method, (GET, routes::GET_ONLINE_MEMBERS) => members::get_online_members(pool, resp).await, /* OWNER */ (POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await, + /* META ROUTE */ + (GET, routes::META) => meta::server_meta(resp).await, _ => { println!("\tNOT FOUND: {}: {}", meth, path); *resp.status_mut() = StatusCode::NOT_FOUND diff --git a/server-api/src/meta.rs b/server-api/src/meta.rs new file mode 100644 index 0000000..71b1a96 --- /dev/null +++ b/server-api/src/meta.rs @@ -0,0 +1,25 @@ +// Basic handler for getting meta data about the server +use std::env::var; + +use hyper::{Response, Body}; +use serde_json::to_string; +use serde::Serialize; + +#[derive( Serialize)] +struct Config { + name: String, + description: String, + url: String, + port: u16 +} + + +pub async fn server_meta(response: &mut Response) { + let payload = Config { + name: var("SERVER_NAME").unwrap_or("No name".into()), + description: var("SERVER_DESCRIPTION").unwrap_or("No description".into()), + url: var("SERVER_URL").expect("Couldn't get url from environment"), + port: var("SERVER_PORT").expect("Couldn't get port from environment").parse::().unwrap(), + }; + *response.body_mut() = Body::from(to_string(&payload).unwrap()); +} \ No newline at end of file diff --git a/server-api/src/routes.rs b/server-api/src/routes.rs index 4742ae5..6929256 100644 --- a/server-api/src/routes.rs +++ b/server-api/src/routes.rs @@ -1,8 +1,8 @@ -// TODO: this whole ass module bro i mean c'mon.... just just clean it type Rstr = &'static str; pub const AUTH_LOGIN: Rstr = "/login"; // requires @id @secret +pub const META: Rstr = "/meta"; // @ perms none @ requires JWT however pub const INVITE_CREATE: Rstr = "/invite/create"; // @ perms::CREATE_INVITE pub const INVITE_JOIN: Rstr = "/join"; // @ none for new accounts