我是Node.js开发的新手,目前正在空闲时间从事宠物项目.
到目前为止,我已经使用passport和passport-jwt为策略创建了JWT身份验证,我在所有RESTful API中都使用它.
现在我想把它与某种Facebook身份验证相结合仍然希望坚持使用令牌身份验证.
目前,这是我生成和获取令牌的方式:
exports.authenticate = function(req, res) {
User.findOne({
email: req.body.email
}, function(err, user) {
if (err)
return res.status(400).send(getErrorMessage(err));
if (!user) {
res.status(400).send({
success: false,
message: 'Authentication failed. User not found.'
});
} else {
if (user.checkPassword(req.body.password)) {
let token = jwt.encode(user, config.secretPhrase);
res.json({
success: true,
token: 'JWT ' + token
});
} else {
res.status(401).send({
success: false,
message: 'Authentication failed. Wrong password.'
});
}
}
});
};
app.route('/api/users/authenticate')
.post(user.authenticate);
Run Code Online (Sandbox Code Playgroud)
并验证我执行以下操作:
let user = …Run Code Online (Sandbox Code Playgroud) 这是我来自路由文件(users.js)的代码
User.findOne({linkedin_id: req.body.linkedin_id}, function(err, linkedinUser) {
if(err) {
console.log('err in finding linkedin user '+err);
}
// if user exits
else if(linkedinUser) {
console.log('user exist');
const token = jwt.sign(linkedinUser, config.secret, {expiresIn: 604800});
res.json({success: true, token: 'JWT '+token, user: {
id: linkedinUser._id,
linkedin_id: linkedinUser.linkedin_id,
name: linkedinUser.name,
username: linkedinUser.username,
email: linkedinUser.email,
lkprofilePic: linkedinUser.profilePic
}, msg: 'user exits'
});
}
// if user doesn't exist
else {
User.create({
linkedin_id: req.body.linkedin_id,
name: req.body.name,
username: req.body.username,
email: req.body.email,
lkprofilePic: req.body.lkprofilePic
}, function(err, result) {
if(err) { …Run Code Online (Sandbox Code Playgroud) 如何安全地删除内置的CRUD模块yo meanjs:crud-module <module-name>?
删除文件夹和服务器文件是否足够?
似乎有各种方法来安装Mean Stack(mean.io)的所有模块.但是,在c9.io中执行此操作的最佳方法是什么?我一直在尝试很多东西,但我似乎并没有把它们全部搞定.c9.io有NodeJs的专用工作区和安装Angular.js的方法,但我想要一切,快速,简单和快速!
注意:我尝试创建一个新工作区(Node.js),删除所有文件并运行以下链接中给出的命令:http: //learn.mean.io/#mean-installation
但是,我收到以下错误消息:
john@tut-04-mean:~/workspace $ cd app && npm install
> meanio@0.6.12 preinstall /home/ubuntu/workspace/app/node_modules/meanio
> node ./scripts/preinstall
npm WARN engine mean-cli@0.9.6: wanted: {"node":"0.10.x","npm":"2.1.x"} (current: {"node":"0.10.33","npm":"1.4.28"})
> mean-health@0.1.7 postinstall /home/ubuntu/workspace/app/node_modules/meanio/node_modules/mean-health
> node ./postinstall.js
> mean-cli@0.9.6 preinstall /home/ubuntu/workspace/app/node_modules/meanio/node_modules/mean-cli
> node ./scripts/preinstall
npm WARN optional dep failed, continuing fsevents@0.3.1
npm WARN engine hawk@0.10.2: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine sntp@0.1.4: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine cryptiles@0.1.3: wanted: {"node":"0.8.x"} (current: {"node":"0.10.33","npm":"1.4.28"})
npm WARN engine hoek@0.7.6: wanted: {"node":"0.8.x"} …Run Code Online (Sandbox Code Playgroud) 我目前正在研究超过25000人使用的Node.js堆栈应用程序,我们特别使用Sails.js框架,我们得到的MongoDB应用程序运行在具有30GB RAM的EC2实例上,数据库运行在Mongolab上基于AWS的集群在EC2所在的同一区域中.我们甚至有一个1.5GB的Elastic Cache Redis实例用于存储.
因此,我们面临的主要和巨大问题是延迟.当我们达到请求应用程序的并发用户的峰值时,我们得到多个超时和sails应用程序达到超过7.5GB的RAM,对API的HTTP请求花费的时间超过15秒(这是不可接受的),甚至得到502和504的响应发送nginx的.
我可以注意到Mongo写入操作是我们的主要延迟问题,但是当存在需求峰值时,即使GET请求也需要很长时间.我无法访问生产服务器,我只有pm2(实际上很棒)和New Relic警报的keymetrics监控工具.
所以,我想知道一些应对这些问题的路线图,也许应该提供更详细的信息,到目前为止,我可以说当没有太多用户时,应用程序看起来很稳定.
要考虑哪些主要因素和设置?
到目前为止,我知道我应该做的,但我不知道有关细节或怎么样了.
恕我直言:
在优化代码时,我发布了另一个stackoverflow问题,其中包含一个我正在遵循的代码模式示例.
您对生产应用有何建议和意见?
我使用passport-facebook登录MEAN堆栈webapp.成功登录后,我想生成一个JSON Web令牌(jwt)并重定向到我的SPA中的页面.(res.redirect('/#/ posts /'+ doc.generateJWT()); - 请参阅下面的相关代码).
我的问题是:如何将JWT发送到重定向页面而不在URL中显示?
码:
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
passport.use(new FacebookStrategy({
clientID: FACEBOOK_APP_ID,
clientSecret: FACEBOOK_APP_SECRET,
callbackURL: FACEBOOK_CALLBACKURL
},
function(accessToken, refreshToken, profile, done) {
process.nextTick(function () {
User.findOne({'fbid':profile.id},function(err, docs) {
if (err){
//console.log('Error in SignUp: '+err);
return res.status(401).json(info);
}
else {
if (docs) {
//console.log('User already exists');
globalid = profile.id;
return done(null,docs);
} else {
// if there is no user with that fbid
// create the user
var …Run Code Online (Sandbox Code Playgroud) 我想更新一个数组值,但我不确定正确的方法,所以我尝试了下面的方法,但没有为我工作.
我的模型,我的模型中的儿童字段
childrens: {
type: Array,
default: ''
}
Run Code Online (Sandbox Code Playgroud)
我的查询,
Employeehierarchy.update({ _id: employeeparent._id} ,{ $set: {"$push": { "childrens": employee._id }} })
.exec(function (err, managerparent) {});
Run Code Online (Sandbox Code Playgroud)
谁能请我帮忙.谢谢.
我在本地运行 Angular 4 应用程序时收到“连接被拒绝”页面。
网址是http://localhost:4200/
使用命令运行应用程序ng serve --open。
更新 1:angular.json
通过一些来源,我发现 Angular cli 文件现在已更改为
angular.json.
以下是详细信息agnular.json
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular-forms": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist",
"index": "src/index.html",
"main": "src/main.ts",
"tsConfig": "src/tsconfig.app.json",
"polyfills": "src/polyfills.ts",
"assets": [
"src/assets",
"src/favicon.ico"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": …Run Code Online (Sandbox Code Playgroud) 我是 Strapi 的新用户。在阅读文档时,我对内容类型和组件感到困惑。这两者之间有什么区别?
我一直在努力运行serve我的 angular 项目,每次遇到一些错误时,我都尝试使用 google 寻找答案,现在达到了一个点,我没有找到任何有用的答案。我下载了一个MEAN堆栈应用程序并尝试运行,但现在出现以下错误
ERROR in ../node_modules/@types/connect/index.d.ts:21:42 - error TS2689: Cannot extend an interface 'http.IncomingMessage'. Did you mean 'implements'?
21 export class IncomingMessage extends http.IncomingMessage {
Run Code Online (Sandbox Code Playgroud)
这是我的package.json文件
{
"name": "opticare",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"build": "ng build",
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/animations": "^8.2.14",
"@angular/common": "^8.2.14",
"@angular/compiler": "^8.2.14",
"@angular/core": "^8.2.14",
"@angular/forms": "^8.2.14", …Run Code Online (Sandbox Code Playgroud) mean-stack ×10
node.js ×6
angular ×3
express ×2
javascript ×2
jwt ×2
mongodb ×2
cloud9-ide ×1
crud ×1
meanjs ×1
mongoose ×1
npm ×1
passport.js ×1
sails.js ×1
strapi ×1