Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当路径中含有app时mount-middlewares报错。。 #6

Open
zaaack opened this issue Jul 25, 2016 · 0 comments
Open

当路径中含有app时mount-middlewares报错。。 #6

zaaack opened this issue Jul 25, 2016 · 0 comments

Comments

@zaaack
Copy link

zaaack commented Jul 25, 2016

比如我git clone --depth=1 https://github.com/moajs/moa2.git moa2app ,
然后npm start就会报这种错:

Starting child process with 'node ./bin/www'
fs.js:856
  return binding.readdir(pathModule._makeLong(path));
                 ^

Error: ENOENT: no such file or directory, scandir '/Users/z/Projects/Node/moa2app/middlewares'
    at Error (native)
    at Object.fs.readdirSync (fs.js:856:18)
    at requireDirectory (/Users/z/Projects/Node/moa2app/node_modules/require-directory/index.js:59:6)
    at m (/Users/z/Projects/Node/moa2app/node_modules/mount-middlewares/index.js:20:10)
    at Object.<anonymous> (/Users/z/Projects/Node/moa2app/app.js:10:50)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/Users/z/Projects/Node/moa2app/bin/www:7:11)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Function.Module.runMain (module.js:447:10)
    at startup (node.js:140:18)
    at node.js:1001:3
Program node ./bin/www exited with code 1

然后debug下mound-middlewares源码

var fs = require('fs')
var requireDirectory = require('require-directory')
var debug = require('debug')('mount-middlewares')

function m (dir) {
  var a = dir.split('app') //竟然是用split的。。

  if (a.length > 1) {
    a.pop()
    a.join('app')
  }else {
    if(fs.existsSync(dir + '/app/middlewares')){
      return requireDirectory(module, dir + "/app/middlewares") 
    }

    throw "mount-middlewares ERROR: " + dir + "里没有app目录"
  }
  var _dir = a[0] + "app/middlewares"
  debug(_dir)
  return requireDirectory(module, _dir)
}

module.exports = m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant