mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-05-01 00:31:09 +00:00
Allow CORS and fix event readiness notification
This commit is contained in:
parent
593da123b6
commit
bcfac0c6b6
3 changed files with 38 additions and 1 deletions
31
Cargo.lock
generated
31
Cargo.lock
generated
|
@ -222,6 +222,7 @@ dependencies = [
|
|||
"bitflags",
|
||||
"clap",
|
||||
"ed25519-dalek",
|
||||
"futures-util",
|
||||
"hex",
|
||||
"humantime",
|
||||
"rand_core",
|
||||
|
@ -233,6 +234,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"tokio",
|
||||
"tokio-stream",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
|
@ -564,6 +566,17 @@ version = "0.3.30"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-sink"
|
||||
version = "0.3.30"
|
||||
|
@ -583,9 +596,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-macro",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1697,6 +1712,22 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
|
|
|
@ -10,6 +10,7 @@ axum = { version = "0.7.5", features = ["tokio"] }
|
|||
bitflags = { version = "2.6.0", features = ["serde"] }
|
||||
clap = { version = "4.5.16", features = ["derive"] }
|
||||
ed25519-dalek = { version = "2.1.1", features = ["digest", "serde"] }
|
||||
futures-util = "0.3.30"
|
||||
hex = { version = "0.4.3", features = ["serde"] }
|
||||
humantime = "2.1.0"
|
||||
rand_core = "0.6.4"
|
||||
|
@ -21,6 +22,7 @@ serde-constant = "0.1.0"
|
|||
serde_json = "1.0.127"
|
||||
tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread", "sync"] }
|
||||
tokio-stream = { version = "0.1.15", features = ["sync"] }
|
||||
tower-http = { version = "0.5.2", features = ["cors"] }
|
||||
tracing = "0.1.40"
|
||||
tracing-subscriber = "0.3.18"
|
||||
uuid = { version = "1.10.0", features = ["serde", "v4"] }
|
||||
|
|
|
@ -93,7 +93,8 @@ async fn main_async(opt: Cli, st: AppState) -> Result<()> {
|
|||
.route("/room/:ruuid/feed.json", get(room_get_feed))
|
||||
.route("/room/:ruuid/event", get(room_event))
|
||||
.route("/room/:ruuid/item", post(room_post_item))
|
||||
.with_state(Arc::new(st));
|
||||
.with_state(Arc::new(st))
|
||||
.layer(tower_http::cors::CorsLayer::permissive());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&opt.listen)
|
||||
.await
|
||||
|
@ -433,5 +434,8 @@ async fn room_event(
|
|||
.expect("serialization cannot fail");
|
||||
Some(Ok::<_, Infallible>(evt))
|
||||
});
|
||||
// NB. Send an empty event immediately to trigger client ready event.
|
||||
let first_event = sse::Event::default().comment("");
|
||||
let stream = futures_util::stream::iter(Some(Ok(first_event))).chain(stream);
|
||||
Ok(sse::Sse::new(stream).keep_alive(sse::KeepAlive::default()))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue