diff --git a/README.md b/README.md index c789462..62be3fc 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ the same route. See the [organisation profile](https://github.com/OpenBikeNet) f The protocol is designed in the [protocol repository](https://github.com/OpenBikeNet/protocol). Ideas and feedback are welcome in its Discussions. +## Public server + +A public instance runs at [openbikenet.cloud](https://openbikenet.cloud). Apps connect to +`wss://openbikenet.cloud/v0`, and `https://openbikenet.cloud/v0/stats` shows which apps are on. + ## Running it With Docker (nothing else needed): diff --git a/crates/server/src/landing.html b/crates/server/src/landing.html new file mode 100644 index 0000000..aa527ac --- /dev/null +++ b/crates/server/src/landing.html @@ -0,0 +1,66 @@ + + + + + +OpenBikeNet server + + + +
+

● OpenBikeNet server

+

A neutral relay that lets riders of different indoor cycling apps meet on the same route.

+

This is a backend for apps. There is nothing to use here in a browser.

+ +

Endpoints

+ + + + +
WS/v0Protocol v0: presence on shared routes
GET/v0/statsConnected apps, riders and usage per app
GET/healthzLiveness check
+ +

Links

+ + + +
+ + diff --git a/crates/server/src/ws.rs b/crates/server/src/ws.rs index e715c4e..c000727 100644 --- a/crates/server/src/ws.rs +++ b/crates/server/src/ws.rs @@ -1,4 +1,4 @@ -//! WebSocket endpoint `/v0` and the stats endpoint `/v0/stats`. +//! WebSocket endpoint `/v0`, the stats endpoint `/v0/stats` and the landing page at `/`. //! //! `presence` is pure and returns addressed deliveries; the [`Hub`] holds one bounded queue per //! connection and sends them. A connection whose queue is full is dropped, so a slow reader can @@ -7,13 +7,13 @@ use std::collections::{HashMap, VecDeque}; use std::net::{IpAddr, SocketAddr}; use std::sync::atomic::{AtomicU16, AtomicU64, Ordering}; -use std::sync::{Arc, Mutex, MutexGuard}; +use std::sync::{Arc, LazyLock, Mutex, MutexGuard}; use std::time::Duration; use axum::extract::ws::{CloseFrame, Message, WebSocket, WebSocketUpgrade}; use axum::extract::{ConnectInfo, State}; use axum::http::{header, HeaderMap, StatusCode}; -use axum::response::{IntoResponse, Response}; +use axum::response::{Html, IntoResponse, Response}; use axum::routing::get; use axum::{Json, Router}; use futures_util::stream::SplitSink; @@ -168,6 +168,7 @@ pub fn spawn_tickers(state: Arc) { pub fn router(state: Arc) -> Router { Router::new() + .route("/", get(landing)) .route("/v0", get(ws_handler)) .route("/v0/stats", get(stats_handler)) .route("/healthz", get(healthz)) @@ -175,6 +176,14 @@ pub fn router(state: Arc) -> Router { .with_state(state) } +/// A static page for people who open the server's address in a browser. +static LANDING: LazyLock = + LazyLock::new(|| include_str!("landing.html").replace("{{VERSION}}", env!("CARGO_PKG_VERSION"))); + +async fn landing() -> Html<&'static str> { + Html(LANDING.as_str()) +} + async fn healthz() -> &'static str { "ok" } diff --git a/crates/server/tests/ws.rs b/crates/server/tests/ws.rs index 0fa2235..3dab2ed 100644 --- a/crates/server/tests/ws.rs +++ b/crates/server/tests/ws.rs @@ -388,3 +388,14 @@ async fn ticker_expires_riders() { assert_eq!(l["reason"], "timeout"); assert_eq!(l["id"], "r1"); } + +#[tokio::test] +async fn landing_page() { + let addr = start(test_config()).await; + let (head, body) = http_get(addr, "/").await; + assert!(head.starts_with("HTTP/1.1 200"), "{head}"); + assert!(head.to_lowercase().contains("content-type: text/html"), "{head}"); + assert!(body.contains("/v0/stats"), "{body}"); + assert!(body.contains("https://github.com/OpenBikeNet"), "{body}"); + assert!(body.contains(env!("CARGO_PKG_VERSION")), "{body}"); +}