-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,53 @@ | ||
mod counters; | ||
|
||
use leptos::*; | ||
use actix_files::{Files}; | ||
use actix_web::*; | ||
use crate::counters::*; | ||
use leptos_actix::{generate_route_list, LeptosRoutes}; | ||
|
||
#[get("/api/events")] | ||
async fn counter_events() -> impl Responder { | ||
use futures::StreamExt; | ||
|
||
let stream = | ||
futures::stream::once(async { crate::counters::get_server_count().await.unwrap_or(0) }) | ||
.chain(COUNT_CHANNEL.clone()) | ||
.map(|value| { | ||
Ok(web::Bytes::from(format!( | ||
"event: message\ndata: {value}\n\n" | ||
))) as Result<web::Bytes> | ||
}); | ||
HttpResponse::Ok() | ||
.insert_header(("Content-Type", "text/event-stream")) | ||
.streaming(stream) | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
|
||
// Explicit server function registration is no longer required | ||
// on the main branch. On 0.3.0 and earlier, uncomment the lines | ||
// below to register the server functions. | ||
// _ = GetServerCount::register(); | ||
// _ = AdjustServerCount::register(); | ||
// _ = ClearServerCount::register(); | ||
|
||
// Setting this to None means we'll be using cargo-leptos and its env vars. | ||
// when not using cargo-leptos None must be replaced with Some("Cargo.toml") | ||
let conf = get_configuration(None).await.unwrap(); | ||
|
||
let addr = conf.leptos_options.site_addr; | ||
let routes = generate_route_list(Counters); | ||
|
||
HttpServer::new(move || { | ||
let leptos_options = &conf.leptos_options; | ||
let site_root = &leptos_options.site_root; | ||
use crate::counters::*; | ||
use actix_files::Files; | ||
use actix_web::*; | ||
use leptos::*; | ||
use leptos_actix::{generate_route_list, LeptosRoutes}; | ||
|
||
#[get("/api/events")] | ||
async fn counter_events() -> impl Responder { | ||
use futures::StreamExt; | ||
|
||
let stream = futures::stream::once(async { | ||
crate::counters::get_server_count().await.unwrap_or(0) | ||
}) | ||
.chain(COUNT_CHANNEL.clone()) | ||
.map(|value| { | ||
Ok(web::Bytes::from(format!( | ||
"event: message\ndata: {value}\n\n" | ||
))) as Result<web::Bytes> | ||
}); | ||
HttpResponse::Ok() | ||
.insert_header(("Content-Type", "text/event-stream")) | ||
.streaming(stream) | ||
} | ||
|
||
App::new() | ||
.service(counter_events) | ||
.leptos_routes(leptos_options.to_owned(), routes.to_owned(), Counters) | ||
.service(Files::new("/", site_root)) | ||
//.wrap(middleware::Compress::default()) | ||
}) | ||
.bind(&addr)? | ||
.run() | ||
.await | ||
} | ||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
// Setting this to None means we'll be using cargo-leptos and its env vars. | ||
// when not using cargo-leptos None must be replaced with Some("Cargo.toml") | ||
let conf = get_configuration(None).await.unwrap(); | ||
|
||
let addr = conf.leptos_options.site_addr; | ||
let routes = generate_route_list(Counters); | ||
|
||
HttpServer::new(move || { | ||
let leptos_options = &conf.leptos_options; | ||
let site_root = &leptos_options.site_root; | ||
|
||
App::new() | ||
.service(counter_events) | ||
.leptos_routes( | ||
leptos_options.to_owned(), | ||
routes.to_owned(), | ||
Counters, | ||
) | ||
.service(Files::new("/", site_root)) | ||
//.wrap(middleware::Compress::default()) | ||
}) | ||
.bind(&addr)? | ||
.run() | ||
.await | ||
} |