aardio的文件下载服务器[代码片段]

我的梦境 提交于 2020-10-07 00:47:44

一直在看aardio的代码, 最近看到一个form嵌入echarts图表的例子,感觉还不错, 但从远端下载echarts.min.js不稳定,偶尔会无法展示,于是就弄了个nginx来本地下载js的方式, 展示效果还不错.  见此: https://gitee.com/wmhx/aardio_project/tree/master/echarts

但aardio自己也有httpserver, 于是又写了一点代码来内嵌一个httpserver的方式来提供js下载服务, 代码如下, 没有全部整合.

//多线程HTTP服务器
import fsys;
import process;
import wsock.tcp.simpleHttpServer;

var server = wsock.tcp.simpleHttpServer( "127.0.0.1" ,/*随机端口*/ );  
server.documentRoot= ..fsys.getCurDir();

var ip,port=server.getLocalIp();
var url = ..string.format("http://%s:%d",ip,port );

process.execute(server.getUrl()); //用浏览器打开

server.run(
	function(response,request,session){ 
		 var file=..io.fullpath(..fsys.getCurDir(),request.path); 
		 if(..io.exist(file)) {  
		 	if(..fsys.isDir(file)){  
		 	    response.write( time.now() );
		 	} else {
				var strData = ..string.load(file);
				response.contentType = ..fsys.mime.fromFile(file);
				response.write(strData)
		 	}
		 }
		 else { response.errorStatus(404); }
	}
)

return {
	ip=ip;
	port=port;
	url=url;	
}

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!