2 Star 11 Fork 4

武松 / flow-chart

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.js 918 Bytes
一键复制 编辑 原始数据 按行查看 历史
newpanjing 提交于 2019-03-10 11:42 . 实现基本功能
/*
创建一个简单的http服务器
*/
var http = require('http');
var baseDir = '';
var path = require('path');
var fs = require('fs');
http.createServer(function (req, res, next) {
var url = req.url;
console.log(`${req.method} ${req.url}`)
if (url == '/') {
url = 'index.html';
}
var index = url.indexOf('?');
if (index != -1) {
url = url.substring(0, index);
}
//读取文件
var ap = path.join(__dirname, baseDir, url);
var exists = fs.existsSync(ap);
if (!exists) {
res.writeHead(404);
res.end('not found.')
return;
}
var readerStream = fs.createReadStream(ap);
readerStream.pipe(res);
// readerStream.on('data', function (data) {
//
// });
//
// res.end(url);
}).on('error', function (err) {
console.error(err);
}).listen(3000);
console.log('listen http://127.0.0.1:3000');
JavaScript
1
https://gitee.com/tompeppa/flow-chart.git
git@gitee.com:tompeppa/flow-chart.git
tompeppa
flow-chart
flow-chart
master

搜索帮助