moajs / moa2 Goto Github PK
View Code? Open in Web Editor NEWMoa2 Core = Moajs with koa 2.x
Home Page: https://github.com/moajs/moa2
License: MIT License
Moa2 Core = Moajs with koa 2.x
Home Page: https://github.com/moajs/moa2
License: MIT License
比如我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
README还是得再改改……
根据步骤
$ git clone --depth=1 https://github.com/moajs/moa2.git <your-project-name> $ cd <your-project-name> $ npm install $ npm start
发现没有bin/www文件,整个项目跑不起来。
`require('../../config/log.js')
const jwt = require('jsonwebtoken')//用来创建和确认用户信息摘要
// 检查用户会话
module.exports = function (ctx, next) {
if (process.env.moas) {
ctx.api_user = {
_id : "55d8702d5472aa887b45f68c"
}
log('当前使用moas运行,不使用token即可访问!')
return next()
}
log('检查post的信息或者url查询参数或者头信息')
//检查post的信息或者url查询参数或者头信息
var token = req.body.token || req.query.token || req.headers['x-access-token']
// 解析 token
if (token) {
// 确认token
jwt.verify(token, 'app.get(superSecret)', function (err, decoded) {
if (err) {
return res.json({ success: false, message: 'token信息错误.' })
} else {
// 如果没问题就把解码后的信息保存到请求中,供后面的路由使用
ctx.api_user = decoded
dir(ctx.api_user)
return next()
}
})
} else {
// 如果没有token,则返回错误
ctx.status = 403
return ctx.body = {
success: false,
message: '没有提供token!'
}
}
}`
这里 req没有 声明,然后 我声明之后 就变成了
<-- POST /api/users xxx POST /api/users 500 9ms - TypeError: Cannot read property 'token' of undefined at module.exports (/Users/thomaslau/WebstormProjects/moa2/app/middlewares/check_api_token.js:25:23)
非常简单又实用的功能
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.