Skip to content

Commit

Permalink
Add version number on web page
Browse files Browse the repository at this point in the history
  • Loading branch information
sorz committed Nov 29, 2017
1 parent d6bcd8e commit f46cb0e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</head>
<body>
<h1>moproxy</h1>
<p>moproxy is running.</p>
<p>moproxy <span id="version"></span> is running.</p>
<button id="refresh">Refresh</button>

<h2>Proxy servers</h2>
Expand All @@ -36,6 +36,7 @@ <h2>Proxy servers</h2>
crossorigin="anonymous"></script>
<script>
const API_SERVERS = "servers";
const API_VERSION = "version";
$(document).ready(update);

function update() {
Expand All @@ -45,6 +46,7 @@ <h2>Proxy servers</h2>
$table.append(newServerRow(server));
}
});
$.get(API_VERSION).done((v) => $('#version').text(`(v${v})`));
}

function newServerRow(info) {
Expand Down
5 changes: 5 additions & 0 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ fn not_found(_context: Context, mut response: Response) {
response.send("page not found");
}

fn version(_context: Context, response: Response) {
response.send(env!("CARGO_PKG_VERSION"));
}

fn servers_json(context: Context, mut response: Response) {
let json_type = ContentType(content_type!(Text / Json; Charset = Utf8));
response.headers_mut().set(json_type);
Expand All @@ -37,6 +41,7 @@ pub fn run_server(bind: SocketAddr, servers: Arc<ServerList>) {
TreeRouter::new() => {
"/" => Get: index as fn(Context, Response),
"/servers" => Get: servers_json,
"/version" => Get: version,
"/*" => Get: not_found,
}
};
Expand Down

0 comments on commit f46cb0e

Please sign in to comment.