005-http-open
Advanced tools
Comparing version 1.0.0 to 1.0.1
34
index.js
@@ -7,11 +7,31 @@ #!/usr/bin/env node | ||
const path=require('path'); | ||
const query=require('querystring'); | ||
const child=require('child_process'); | ||
const getaddress=require('./getaddress') | ||
const port=3000; | ||
const tool=require('./tool') | ||
const port=8000; | ||
const server=http.createServer((req,res)=>{ | ||
let ws=fs.createReadStream(path.join(__dirname,'index.html')) | ||
ws.pipe(res); | ||
ws.on('end',()=>{ | ||
let file=path.resolve(path.join('.',query.unescape(req.url))); | ||
if(fs.existsSync(file)){ | ||
if(tool.isfile(file)){ | ||
fs.readFile(file,(err,data)=>{ | ||
res.end(data) | ||
}) | ||
}else if(tool.isdir(file)){ | ||
let lis=''; | ||
fs.readdirSync(file).forEach(v=>{ | ||
lis+= ` | ||
<li> | ||
<a href=${path.join(query.unescape(req.url),v)}> | ||
${v+(tool.isdir(path.join(file,v))?'/':'')} | ||
</a> | ||
</li> | ||
` | ||
}) | ||
let html= fs.readFileSync(path.join(__dirname,'index.html')).toString(); | ||
res.end(html.replace("$",lis)); | ||
} | ||
}else{ | ||
res.writeHead(404); | ||
res.end(); | ||
}) | ||
} | ||
}) | ||
@@ -21,5 +41,5 @@ server.listen(port,()=>{ | ||
protocol:'http', | ||
hostname:getaddress(), | ||
hostname:tool.getaddress(), | ||
port:port | ||
})]) | ||
}) |
{ | ||
"name": "005-http-open", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
2370
67
3