mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
fix(validate) root: crash when --no-root used
This commit is contained in:
parent
3931915ee8
commit
383f0ce39f
3 changed files with 32 additions and 4 deletions
|
|
@ -97,7 +97,7 @@ if (args.version) {
|
|||
readConfig(args.config);
|
||||
|
||||
const options = {
|
||||
root: args.root,
|
||||
root: args.root || '/', /* --no-root */
|
||||
editor: args.editor,
|
||||
packer: args.packer,
|
||||
prefix: args.prefix
|
||||
|
|
|
|||
|
|
@ -9,12 +9,16 @@ module.exports.packer = packer;
|
|||
function root(dir, fn) {
|
||||
var fs;
|
||||
|
||||
if (typeof dir !== 'string')
|
||||
throw Error('dir should be a string');
|
||||
|
||||
if (dir !== '/') {
|
||||
fs = require('fs');
|
||||
fs = require('fs');
|
||||
fs.stat(dir, function(error) {
|
||||
if (error)
|
||||
exit('cloudcmd --root: %s', error.message);
|
||||
else if (typeof fn === 'function')
|
||||
return exit('cloudcmd --root: %s', error.message);
|
||||
|
||||
if (typeof fn === 'function')
|
||||
fn('root:', dir);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
24
test/lib/validate.js
Normal file
24
test/lib/validate.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
const test = require('tape');
|
||||
const root = '../../';
|
||||
const validate = require(root + 'lib/server/validate');
|
||||
|
||||
const before = require('../before');
|
||||
|
||||
test('validate: root: bad', (t) => {
|
||||
const config = {
|
||||
root: Math.random()
|
||||
};
|
||||
const fn = () => {
|
||||
before({config}, (port, after) => {
|
||||
t.fail('should not create server');
|
||||
after();
|
||||
t.end();
|
||||
});
|
||||
};
|
||||
|
||||
t.throws(fn, /dir should be a string/, 'should throw');
|
||||
t.end();
|
||||
});
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue