New server meta endpoint to help out clients remember stuff about that server
This commit is contained in:
parent
76fc2f66b3
commit
2fb24ee45e
@ -5,3 +5,10 @@ DATABASE_USER=freechat_dev
|
|||||||
DATABASE_HOST=localhost
|
DATABASE_HOST=localhost
|
||||||
DATABASE_PORT=3306
|
DATABASE_PORT=3306
|
||||||
REDIS_URL=redis://127.0.0.1:6379
|
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
|
@ -173,7 +173,8 @@ def auth_tests(worker):
|
|||||||
# fail 400
|
# fail 400
|
||||||
worker.post('/channels/create', jwt=False, name=f'succ', kind=2)
|
worker.post('/channels/create', jwt=False, name=f'succ', kind=2)
|
||||||
|
|
||||||
# fail
|
# pass 200
|
||||||
|
worker.get('/meta', jwt=jwt)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
worker = Test(create_admin=False, init_verbose=True)
|
worker = Test(create_admin=False, init_verbose=True)
|
||||||
|
@ -30,6 +30,7 @@ use auth::AuthReason;
|
|||||||
mod auth;
|
mod auth;
|
||||||
|
|
||||||
mod routes;
|
mod routes;
|
||||||
|
mod meta;
|
||||||
mod invites;
|
mod invites;
|
||||||
mod channels;
|
mod channels;
|
||||||
mod members;
|
mod members;
|
||||||
@ -65,6 +66,8 @@ async fn route_dispatcher(pool: &Pool, resp: &mut Response<Body>, meth: &Method,
|
|||||||
(GET, routes::GET_ONLINE_MEMBERS) => members::get_online_members(pool, resp).await,
|
(GET, routes::GET_ONLINE_MEMBERS) => members::get_online_members(pool, resp).await,
|
||||||
/* OWNER */
|
/* OWNER */
|
||||||
(POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await,
|
(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);
|
println!("\tNOT FOUND: {}: {}", meth, path);
|
||||||
*resp.status_mut() = StatusCode::NOT_FOUND
|
*resp.status_mut() = StatusCode::NOT_FOUND
|
||||||
|
25
server-api/src/meta.rs
Normal file
25
server-api/src/meta.rs
Normal file
@ -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<Body>) {
|
||||||
|
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::<u16>().unwrap(),
|
||||||
|
};
|
||||||
|
*response.body_mut() = Body::from(to_string(&payload).unwrap());
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
// TODO: this whole ass module bro i mean c'mon.... just just clean it
|
|
||||||
type Rstr = &'static str;
|
type Rstr = &'static str;
|
||||||
|
|
||||||
pub const AUTH_LOGIN: Rstr = "/login"; // requires @id @secret
|
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_CREATE: Rstr = "/invite/create"; // @ perms::CREATE_INVITE
|
||||||
pub const INVITE_JOIN: Rstr = "/join"; // @ none for new accounts
|
pub const INVITE_JOIN: Rstr = "/join"; // @ none for new accounts
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user