@@ -16,6 +16,7 @@ use std::task::{Context, Poll};
1616use actix_cors:: Cors ;
1717use actix_web:: web:: { Bytes , Data , Path } ;
1818use actix_web:: { get, post, web, App , Error , HttpResponse , HttpServer , Responder } ;
19+ use clap:: { crate_version, clap_app} ;
1920use futures:: Stream ;
2021use serde:: { Deserialize , Serialize } ;
2122use tokio:: sync:: broadcast:: { channel, Receiver , Sender } ;
@@ -25,8 +26,17 @@ use tokio::sync::broadcast::{channel, Receiver, Sender};
2526async fn main ( ) -> std:: io:: Result < ( ) > {
2627 env_logger:: init ( ) ;
2728
29+ let matches = clap_app ! ( myapp =>
30+ ( version: crate_version!( ) )
31+ ( author: "Ronak B." )
32+ ( about: "A sse-based pubsub with different channels" )
33+ ( @arg HOST : --host +takes_value "Address to host on" )
34+ ( @arg PORT : --port +takes_value "Port to host on" )
35+ ) . get_matches ( ) ;
36+
2837 let data = BroadcasterMap :: create ( ) ;
2938
39+
3040 HttpServer :: new ( move || {
3141 App :: new ( )
3242 . wrap (
@@ -39,7 +49,9 @@ async fn main() -> std::io::Result<()> {
3949 . service ( new_client)
4050 . service ( broadcast)
4151 } )
42- . bind ( "127.0.0.1:8080" ) ?
52+ . bind ( format ! ( "{}:{}" ,
53+ matches. value_of( "HOST" ) . unwrap_or( "127.0.0.1" ) ,
54+ matches. value_of( "PORT" ) . unwrap_or( "8080" ) ) ) ?
4355 . run ( )
4456 . await
4557}
0 commit comments