我继承了在Angular / Sails / PostgreSQL中开发的半完成项目(app)
我以前没有使用过Angular,Sails.js或PostgreSQL
该应用程序正常运行,目前正在运行,并且有几个重要用户正在使用它。
此应用程序在暂存时根本没有运行,直到我执行'mkdir logs',然后有'ReferenceError:Promise未定义',所以我认为该应用程序可能是在live上开发的/在live上配置的
我已经设置了一个本地开发环境,我也看到了这个'ReferenceError'错误。
我怀疑配置问题是导致此问题的原因,但如果是这种情况,我不知道我错过了什么。
我尝试了各种命令,例如'npm install','npm update',以及降级各种软件包,目前代码,package.json等是live的精确副本,模块应该完全相同版本
我可以创建一个新的sails项目,在浏览器中查看时一切正常。
壳体升帆输出:
vagrant@sails-vagrant-machine:~/dev/project$ sails lift
info: Starting app...
i18n:debug will write to /home/vagrant/dev/project/config/locales/en.json +0ms
i18n:debug read /home/vagrant/dev/project/config/locales/en.json for locale: en +0ms
i18n:debug will write to /home/vagrant/dev/project/config/locales/es.json +1ms
i18n:debug read /home/vagrant/dev/project/config/locales/es.json for locale: es +1ms
i18n:debug will write to /home/vagrant/dev/project/config/locales/fr.json +0ms
i18n:debug read /home/vagrant/dev/project/config/locales/fr.json for locale: fr +1ms
i18n:debug will write to /home/vagrant/dev/project/config/locales/de.json +0ms
i18n:debug read /home/vagrant/dev/project/config/locales/de.json for locale: de +0ms
[ReferenceError: Promise is not defined]
undefined
Unhandled rejection TypeError: Cannot read property 'message' of undefined
at /home/vagrant/dev/project/api/controllers/AuthController.js:23:34
at Strategy.strategy.error (/home/vagrant/dev/project/node_modules/passport/lib/middleware/authenticate.js:333:18)
at verified (/home/vagrant/dev/project/node_modules/passport-local/lib/strategy.js:81:28)
at /home/vagrant/dev/project/config/passport.js:79:20
at tryCatcher (/home/vagrant/dev/project/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:507:31)
at Promise._settlePromiseAt (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (/home/vagrant/dev/project/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:133:10)
at Async.drainQueues (/home/vagrant/dev/project/node_modules/bluebird/js/main/async.js:15:14)
at process._tickDomainCallback (node.js:463:13)
的package.json:
{
"name": "project",
"private": true,
"version": "0.0.0",
"description": "a Sails application",
"keywords": [],
"dependencies": {
"ap": "^0.2.0",
"async": "^1.4.2",
"bcrypt": "~0.8.0",
"bluebird": "^2.10.0",
"crypto": "0.0.3",
"ejs": "~0.8.4",
"email-templates": "^2.0.1",
"forever": "^0.15.1",
"grunt": "0.4.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-coffee": "~0.10.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-jst": "~0.6.0",
"grunt-contrib-less": "0.11.1",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-sails-linker": "~0.9.5",
"grunt-sync": "~0.0.4",
"html-pdf": "^1.4.0",
"include-all": "~0.1.3",
"less": "^2.5.1",
"mandrill-api": "^1.0.45",
"moment": "^2.10.6",
"passport": "~0.2.1",
"passport-local": "~1.0.0",
"postgres-array": "^1.0.0",
"postgres-bytea": "^1.0.0",
"postgres-date": "^1.0.0",
"rc": "~0.5.0",
"request": "^2.62.0",
"sails": "~0.11.0",
"sails-disk": "~0.10.0",
"sails-postgresql": "^0.10.16",
"sp": "^0.1.3",
"waterline": "^0.10.26",
"winston": "^1.0.1"
},
"scripts": {
"start": "node app.js",
"debug": "node debug app.js"
},
"main": "app.js",
"repository": {
"type": "git",
"url": "git://github.com/**.....**/project.git"
},
"author": "**.....**",
"license": ""
}
API /控制器/ AuthController.js:
/**
* AuthController
*
* @description :: Server-side logic for managing auths
* @help :: See http://links.sailsjs.org/docs/controllers
*/
var passport = require('passport');
var bcrypt = require('bcrypt');
module.exports = {
_config: {
actions: false,
shortcuts: false,
rest: false
},
login: function(req, res) {
passport.authenticate('local', function(err, user, info) {
console.log(err);
console.log(user);
if ((err) || (!user)) {
return res.send({
message: info.message,
user: user
});
} else {
req.logIn(user, function (err) {
if (err) res.send(err);
return res.send({
message: info.message,
user: user
});
});
}
})(req, res);
},
logout: function(req, res) {
req.logout();
res.redirect('/');
}
};
我真的很感激你的帮助。
答案 0 :(得分:1)
info
不是passport.authenticate
行的对象。
passport.authenticate('local', function(err, user, info) {
您已记录err
和user
,但未记录info
- 如果您已登录info
,那么您会看到undefined
,所以您不能在此行使用它的message
属性:
return res.send({
message: info.message,
user: user
});