@@ -22,11 +22,7 @@ async fn web_socket_route(req: HttpRequest, stream: web::Payload) -> Result<Http
22
22
ws:: start (
23
23
WsActor {
24
24
heartbeat : Instant :: now ( ) ,
25
- rx : if let Some ( rx) = & state. rx {
26
- Some ( rx. clone ( ) )
27
- } else {
28
- None
29
- } ,
25
+ rx : state. rx . as_ref ( ) . cloned ( ) ,
30
26
} ,
31
27
& req,
32
28
stream,
@@ -38,39 +34,37 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Error> {
38
34
let path = req. uri ( ) . path ( ) ;
39
35
let mut path = PathBuf :: from ( & path[ 1 ..] ) ; // rm / from path
40
36
let state: & WebServerState = req. app_data ( ) . unwrap ( ) ;
41
- if {
42
- // if uri contains an extension then its a static file
43
- if let Some ( ext) = path. extension ( ) {
44
- let ext = ext. to_str ( ) . unwrap ( ) ;
45
- // if extension is html then serve index.html
46
- let is_html = ext == "html" ;
47
- if !is_html {
48
- //check if file exists in output dir
49
- let output_path = PathBuf :: from ( & state. output_dir ) . join ( & path) ;
50
- if output_path. exists ( ) {
51
- path = output_path;
52
- } else if let Some ( public_dir) = & state. public_dir {
53
- path = PathBuf :: from ( public_dir) . join ( & path) ;
54
- } else {
55
- return Ok ( HttpResponse :: new ( StatusCode :: NOT_FOUND ) ) ;
56
- }
37
+ // if uri contains an extension then its a static file
38
+ if if let Some ( ext) = path. extension ( ) {
39
+ let ext = ext. to_str ( ) . unwrap ( ) ;
40
+ // if extension is html then serve index.html
41
+ let is_html = ext == "html" ;
42
+ if !is_html {
43
+ //check if file exists in output dir
44
+ let output_path = PathBuf :: from ( & state. output_dir ) . join ( & path) ;
45
+ if output_path. exists ( ) {
46
+ path = output_path;
47
+ } else if let Some ( public_dir) = & state. public_dir {
48
+ path = PathBuf :: from ( public_dir) . join ( & path) ;
49
+ } else {
50
+ return Ok ( HttpResponse :: new ( StatusCode :: NOT_FOUND ) ) ;
57
51
}
58
- is_html
59
- } else {
60
- // if path has no extension then serve html
61
- true
62
52
}
53
+ is_html
54
+ } else {
55
+ // if path has no extension then serve html
56
+ true
63
57
} {
64
58
path = PathBuf :: from ( & state. output_dir ) . join ( "index.html" )
65
59
}
66
60
// if path exist then serve it
67
- return if path. exists ( ) {
61
+ if path. exists ( ) {
68
62
Ok ( actix_files:: NamedFile :: open ( path) ?
69
63
. prefer_utf8 ( true )
70
64
. into_response ( & req) )
71
65
} else {
72
66
Ok ( HttpResponse :: new ( StatusCode :: NOT_FOUND ) )
73
- } ;
67
+ }
74
68
}
75
69
76
70
pub fn start_web_server (
0 commit comments