File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ import  http  from  'http' ; 
2+ import  fs  from  'fs' ; 
3+ import  path  from  'path' ; 
4+ import  {  exec  }  from  'child_process' ; 
5+ 
6+ // 创建HTTP服务器 
7+ const  server  =  http . createServer ( ( req ,  res )  =>  { 
8+ 	// 处理根路径请求 
9+ 	const  purePath  =  req . url ?. slice ( 0 ,  req . url . indexOf ( '?' ) ) 
10+ 	if  ( ! purePath  ||  purePath  ===  '/' )  { 
11+ 		const  html  =  fs . readFileSync ( path . join ( __dirname ,  '../server/index.html' ) ) ; 
12+ 		res . writeHead ( 200 ,  {  'Content-Type' : 'text/html; charset=utf-8' ,   } ) ; 
13+ 		return  res . end ( html ) ; 
14+ 	} 
15+ 
16+ 	// 处理其他静态文件 
17+ 	const  filePath  =  path . join ( __dirname ,  req . url  as  string ) ; 
18+ 	if  ( fs . existsSync ( filePath ) )  { 
19+ 		const  content  =  fs . readFileSync ( filePath ) ; 
20+ 		res . end ( content ) ; 
21+ 	}  else  { 
22+ 		res . writeHead ( 404 ) ; 
23+ 		res . end ( 'Not found' ) ; 
24+ 	} 
25+ } ) ; 
26+ 
27+ const  port  =  56789 ; 
28+ const  baseURL  =  `http://localhost:${ port }  ` 
29+ const  url  =  `${ baseURL }  ?ws=ws://localhost:${ port }  ` 
30+ 
31+ // 启动服务 
32+ server . listen ( port ,  ( )  =>  { 
33+ 	console . log ( `Server running at ${ baseURL }  ` ) ; 
34+ 	exec ( `open "${ url }  "` ) ; 
35+ } ) ; 
Original file line number Diff line number Diff line change 1+ <!-- index.html --> 
2+ <!DOCTYPE html>  
3+ < html   lang ="en "> 
4+ < head > 
5+   < title > CLI Browser Interaction</ title > 
6+ </ head > 
7+ < body > 
8+   < h1 > 操作监控页面</ h1 > 
9+ 
10+   <!-- 示例交互元素 --> 
11+   < button  id ="testBtn "> 测试按钮</ button > 
12+   < form  id ="testForm "> 
13+     < input  type ="text " name ="username "> 
14+     < button  type ="submit "> 提交</ button > 
15+   </ form > 
16+ 
17+   <!-- 注入监控脚本 --> 
18+   < script > 
19+     // 这里放置之前提供的WebSocket客户端代码 
20+   </ script > 
21+ </ body > 
22+ </ html > 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments