fis-command-server
Advanced tools
Comparing version 0.7.0-beta to 0.7.0-beta2
@@ -33,3 +33,4 @@ var step = require('step'); | ||
var install = spawn('npm', args); | ||
var npm = process.platform === "win32" ? "npm.cmd" : "npm"; | ||
var install = spawn(npm, args); | ||
install.stdout.pipe(process.stdout); | ||
@@ -77,7 +78,6 @@ install.stderr.pipe(process.stderr); | ||
var args = [ | ||
path.join(__dirname, 'node', 'boot.js'), | ||
'--script', | ||
script | ||
__dirname + '/node/boot.js' | ||
]; | ||
opt.script = script; | ||
fis.util.map(opt, function(key, value){ | ||
@@ -87,3 +87,3 @@ args.push('--' + key, String(value)); | ||
var server = spawn(process.execPath, args, { cwd : opt.root, detached: true }); | ||
var server = spawn(process.execPath, args, { cwd : __dirname, detached: true }); | ||
@@ -90,0 +90,0 @@ var log = ''; |
@@ -37,3 +37,3 @@ var cluster = require("cluster"); | ||
logger.takecare(worker.process.stdout); | ||
logger.takecare(worker.process.stderr); | ||
worker.process.stderr.pipe(process.stderr); | ||
@@ -40,0 +40,0 @@ // 为了让 lib/node.js 能够检测到服务器起来了。 |
var express = require('express'); | ||
var args = process.argv.join(' '); | ||
var port = /\s\-\-port\s*(\d+)(?:\s|$)/.test(args) ? ~~RegExp.$1 : 8080; | ||
var args = process.argv.join('|'); | ||
var port = /\-\-port\|(\d+)(?:\||$)/.test(args) ? ~~RegExp.$1 : 8080; | ||
var path = require('path'); | ||
var DOCUMENT_ROOT = path.resolve(/\s\-\-root\s*(\S*)(?:\s|$)/.test(args) ? RegExp.$1 : process.cwd()); | ||
var DOCUMENT_ROOT = path.resolve(/\-\-root\|(.*?)(?:\||$)/.test(args) ? RegExp.$1 : process.cwd()); | ||
var app = express(); | ||
console.log(DOCUMENT_ROOT); | ||
// server.conf 功能 | ||
@@ -18,18 +20,50 @@ // 支持 test/ 目录下面 .js js 脚本功能和 json 预览功能。 | ||
// 静态文件列表。 | ||
app.use(require('serve-index')(DOCUMENT_ROOT, { | ||
app.use((function() { | ||
var url = require('url'); | ||
var fs = require('fs'); | ||
// 不需要显示 /server.js | ||
// 不现实 node_modules 目录 | ||
filter: function(filename, index, files, dir) { | ||
dir = dir.substr(DOCUMENT_ROOT.length); | ||
return function(req, res, next) { | ||
var pathname = url.parse(req.url).pathname; | ||
var fullpath = path.join(DOCUMENT_ROOT, pathname); | ||
if (filename === 'server.js' && dir === '/') { | ||
return false; | ||
} else if (filename === 'node_modules') { | ||
return false; | ||
if (/\/$/.test(pathname) && fs.existsSync(fullpath)) { | ||
var stat = fs.statSync(fullpath); | ||
if (stat.isDirectory()) { | ||
var html = ''; | ||
var files = fs.readdirSync(fullpath); | ||
html = '<!doctype html>'; | ||
html += '<html>'; | ||
html += '<head>'; | ||
html += '<title>' + pathname + '</title>'; | ||
html += '</head>'; | ||
html += '<body>'; | ||
html += '<h1> - ' + pathname + '</h1>'; | ||
html += '<div id="file-list">'; | ||
html += '<ul>'; | ||
if(pathname != '/'){ | ||
html += '<li><a href="' + pathname + '..">..</a></li>'; | ||
} | ||
files.forEach(function(item) { | ||
var s_url = path.join(pathname, item); | ||
html += '<li><a href="' + s_url + '">'+ item + '</a></li>'; | ||
}); | ||
html += '</ul>'; | ||
html += '</div>'; | ||
html += '</body>'; | ||
html += '</html>'; | ||
res.send(html); | ||
return; | ||
} | ||
} | ||
return true; | ||
} | ||
})); | ||
next(); | ||
}; | ||
})()); | ||
@@ -36,0 +70,0 @@ // 静态文件输出 |
{ | ||
"name": "fis-command-server", | ||
"description": "fis server command.", | ||
"version": "0.7.0-beta", | ||
"version": "0.7.0-beta2", | ||
"author": "FIS Team <fis@baidu.com>", | ||
@@ -6,0 +6,0 @@ "homepage": "http://fis.baidu.com/", |
4929059
919
12