File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ [package ]
2+ name  = " file_server" 
3+ version  = " 0.1.0" 
4+ edition  = " 2021" 
5+ 
6+ #  See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+ 
8+ [dependencies ]
9+ silent  = { path  = " ../../silent" 
10+ async-trait  = " 0.1.68" 
11+ tokio  = { version  = " 1" features  = [" full" 
Original file line number Diff line number Diff line change 1+ use  silent:: prelude:: * ; 
2+ use  std:: sync:: Arc ; 
3+ 
4+ fn  main ( )  { 
5+     logger:: fmt ( ) . init ( ) ; 
6+     if  !std:: path:: Path :: new ( "static" ) . is_dir ( )  { 
7+         std:: fs:: create_dir ( "static" ) . unwrap ( ) ; 
8+         std:: fs:: write ( 
9+             "./static/index.html" , 
10+             r#"<!DOCTYPE html> 
11+ <html> 
12+ <head> 
13+     <meta charset="utf-8"> 
14+     <title>Silent</title> 
15+ </head> 
16+ <body> 
17+ 
18+ <h1>我的第一个标题</h1> 
19+ 
20+ <p>我的第一个段落。</p> 
21+ 
22+ </body> 
23+ </html>"# , 
24+         ) 
25+         . unwrap ( ) ; 
26+     } 
27+     let  mut  route = Route :: new ( "<path:**>" ) ; 
28+     route
29+         . get_handler_mut ( ) 
30+         . insert ( Method :: GET ,  Arc :: new ( static_handler ( "static" ) ) ) ; 
31+     Server :: new ( ) . bind_route ( route) . run ( ) ; 
32+ } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments