|
- var html = /**
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
- <title>Directory listing for /</title>
- <body>
- <h2>Directory listing for <?=rget(2,...)?></h2>
- <hr>
- <ul>
- <?
- import console;
- import fsys;
- var path = ...;
- var i = 0;
- fsys.enum( path, "*.*",
- function(dir,filename,fullpath,findData){
- i=i+1;
- if(filename){
- print('<li><a href="'+filename+'">'+tostring(i)+") "+filename+'</a><br>\r\n');
- }
- else{
- print("<li><a href='"+dir+"/'>"+tostring(i)+") "+dir+"/</a><br>")
- }
- }
- ,false
- );
- ?>
- </ul>
- <hr>
- </body>
- </html>
- **/;
- if !io.exist("/html.aardio") string.save("/html.aardio", html);
- import wsock.tcp.simpleHttpServer;
- import console;
- import process;
- var server = wsock.tcp.simpleHttpServer("127.0.0.1");
- process.execute(server.getUrl());
- console.log("启动:",server.getUrl());
- server.run(
- function(response,request,winform){
- import fsys;
- var path = request.path;
- //设置根目录
- path = fsys.path.replaceDir(path,"/","c:");
- console.log(request.method,request.path);
- if (fsys.isDir(path))
- {
- response.loadcode("/html.aardio",path,request.path)
- }
- else {
- response.loadcode( path );
- }
- },winform
- );
复制代码
可以通过这句代码设置根目录
path = fsys.path.replaceDir(path,"/","c:\");
但是好像simpleHttpServer中限制了根目录只能是当前运行的目录
if( ! ..fsys.path.ischild( "/",path ) ){
return response.errorStatus(403);
}
|
|