mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-02 12:35:33 +00:00
refactor(webapi)!: put all API under path /_blah
This commit is contained in:
parent
ab756f78ab
commit
0c28c00c3d
5 changed files with 34 additions and 28 deletions
|
@ -129,7 +129,7 @@ impl AppState {
|
|||
type ArcState = State<Arc<AppState>>;
|
||||
|
||||
pub fn router(st: Arc<AppState>) -> Router {
|
||||
Router::new()
|
||||
let router = Router::new()
|
||||
.route("/ws", get(handle_ws))
|
||||
.route("/user/me", get(user_get).post(user_register))
|
||||
.route("/room", get(room_list))
|
||||
|
@ -153,7 +153,8 @@ pub fn router(st: Arc<AppState>) -> Router {
|
|||
HeaderName::from_static(X_BLAH_DIFFICULTY),
|
||||
]),
|
||||
)
|
||||
.with_state(st)
|
||||
.with_state(st);
|
||||
Router::new().nest("/_blah", router)
|
||||
}
|
||||
|
||||
type RE<T> = R<T, ApiError>;
|
||||
|
|
|
@ -95,8 +95,9 @@ fn socket_activate() {
|
|||
}
|
||||
|
||||
let resp = rt.block_on(async {
|
||||
let url = format!("http://127.0.0.1:{local_port}/_blah/room?filter=public");
|
||||
let fut = async {
|
||||
reqwest::get(format!("http://127.0.0.1:{local_port}/room?filter=public"))
|
||||
reqwest::get(url)
|
||||
.await
|
||||
.unwrap()
|
||||
.error_for_status()
|
||||
|
|
|
@ -130,7 +130,11 @@ struct Server {
|
|||
|
||||
impl Server {
|
||||
fn url(&self, rhs: impl fmt::Display) -> String {
|
||||
format!("http://{}:{}{}", LOCALHOST, self.port, rhs)
|
||||
format!("{}/_blah{}", self.domain(), rhs)
|
||||
}
|
||||
|
||||
fn domain(&self) -> String {
|
||||
format!("http://{}:{}", LOCALHOST, self.port)
|
||||
}
|
||||
|
||||
fn rng(&self) -> impl DerefMut<Target = impl RngCore> + use<'_> {
|
||||
|
@ -881,7 +885,7 @@ async fn register(server: Server) {
|
|||
register_fast(&req)
|
||||
.await
|
||||
.expect_api_err(StatusCode::BAD_REQUEST, "invalid_server_url");
|
||||
req.server_url = server.url("").parse().unwrap();
|
||||
req.server_url = server.domain().parse().unwrap();
|
||||
|
||||
register_fast(&req)
|
||||
.await
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue