customizable page title

This commit is contained in:
mbecker20
2023-03-06 02:07:08 +00:00
parent 5135a9c228
commit 97f582b381
5 changed files with 27 additions and 1 deletions

View File

@@ -62,6 +62,7 @@ pub fn gen_core_config(sub_matches: &ArgMatches) {
.map(|p| p.to_owned());
let config = CoreConfig {
title: String::from("monitor"),
host,
port,
jwt_valid_for,

View File

@@ -1,3 +1,6 @@
# optional. this will be the document title on the web page (shows up as text in the browser tab). default is 'monitor'
title = "monitor"
# this should be the url used to access monitor in browser, potentially behind DNS, eg https://monitor.mogh.tech or http://12.34.56.78:9000
host = "https://monitor.mogh.tech"

View File

@@ -44,6 +44,10 @@ struct UserId {
pub fn router() -> Router {
Router::new()
.route(
"/title",
get(|state: StateExtension| async move { state.config.title.clone() }),
)
.route("/user", get(get_request_user))
.nest("/listener", github_listener::router())
.nest(

View File

@@ -49,11 +49,18 @@ import { generateQuery, QueryObject } from "./helpers";
export class Client {
loginOptions: LoginOptions | undefined;
monitorTitle: string | undefined;
constructor(private baseURL: string, public token: string | null) {}
async initialize() {
this.loginOptions = await this.get_login_options();
const [loginOptions, monitorTitle] = await Promise.all([
this.get_login_options(),
this.get_monitor_title(),
]);
this.loginOptions = loginOptions;
this.monitorTitle = monitorTitle;
document.title = monitorTitle;
const params = new URLSearchParams(location.search);
const exchange_token = params.get("token");
if (exchange_token) {
@@ -138,6 +145,10 @@ export class Client {
return this.post("/api/update_description", body);
}
get_monitor_title(): Promise<string> {
return this.get("/api/title");
}
// deployment
list_deployments(

View File

@@ -17,6 +17,9 @@ pub type SecretsMap = HashMap<String, String>; // these are used for injection i
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CoreConfig {
#[serde(default = "default_title")]
pub title: String,
// the host to use with oauth redirect url, whatever host the user hits to access monitor. eg 'https://monitor.mogh.tech'
pub host: String,
@@ -71,6 +74,10 @@ pub struct CoreConfig {
pub aws: AwsBuilderConfig,
}
fn default_title() -> String {
String::from("monitor")
}
fn default_core_port() -> u16 {
9000
}