小编Kun*_*ndu的帖子

Passport js无法在跨域中维护会话

我使用护照JS,express和mongoose来制作API.当我在同一个域中测试它时,它保持会话并正常工作.但是在跨域中它失败了.任何线索如何使用相同的配置在跨域维护会话.以下是代码

 allowCrossDomain = function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
    res.header("Access-Control-Allow-Headers", req.headers["access-control-request-headers"]);
    // res.header("Access-Control-Allow-Credentials", "true");
    if ("OPTIONS" == req.method) {
        res.send(200);
    } else {
        next();
    }

  //allow all crossDomain request
app.use(allowCrossDomain);

//session handling
app.use(express.cookieParser("gallery"));
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());

app.use(function(req, res, next) {
    // check if client sent cookie
    var cookie = req.cookies.cokkieName;
    if (cookie === undefined) {
        //set up cookie here by a random number
        });
    }
    next(); // <-- important!
});
passport.use(new LocalStrategy({
    usernameField: "email" …
Run Code Online (Sandbox Code Playgroud)

node.js cors express passport.js

12
推荐指数
3
解决办法
9165
查看次数

无法从解析云更新我的收藏?

我在解析云代码时面临一个问题.以下是我在gamescore表中更新分数和更改日期.但它没有用.虽然我在我的网络代码中做同样的事情,但它工作正常.我在这里做错了吗?

'use strict';
var GameScore = Parse.Object.extend('GameScore');
Parse.Cloud.define('editScore', function(req, res) {
  var query = new Parse.Query(GameScore);
  query.get(req.params.objectId, {
    success: function(gameScore) {
      gameScore.set('score', req.params.score);
      gameScore.set('date', req.params.date);
      gameScore.save(null);
      gameScore.fetch(myCallback);
    },
    error: function(err) {
      return res.error(err);
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

如果是这样,请帮助我,以便我可以使它工作.

javascript parse-platform parse-cloud-code

9
推荐指数
1
解决办法
566
查看次数

如何在mongoose中找到数组中的对象

我有一个如下的架构: -

var P = {
     s : [{
         data : [],
         sec : mongoose.Schema.Types.ObjectId
     }]
 };
Run Code Online (Sandbox Code Playgroud)

现在我想只查找截面的对象而不是整行.喜欢如果我传递sec值,我只想要s.datasec对象的值.

例如: -

{ s : [ 
    {
       data : [],
       sec : '52b9830cadaa9d273200000d'
    },{
        data : [],
       sec : '52b9830cadaa9d2732000005'
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

结果应该看起来像 -

 {
    data : [],
    sec : '52b9830cadaa9d2732000005'
 }
Run Code Online (Sandbox Code Playgroud)

我不想要所有的整排.可能吗?如果是,那么请帮助我.

arrays object mongoose mongodb node.js

3
推荐指数
1
解决办法
9370
查看次数

$ unset在mongoose中不起作用

我的架构如下: -

var Schema1 = new mongoose.Schema({
  name: String,
  description: String,
  version: [{
    id: String,
    status: Number
 }]
});
Run Code Online (Sandbox Code Playgroud)

我想取消设置版本字段.我尝试以下代码: -

Schema1.update({}, {
 $unset: {
  version: 1
  }
 }, {
 multi: true
}).exec(function(err, count) {
 console.log(err, count)
});
Run Code Online (Sandbox Code Playgroud)

它给了我以下输出: -

null 10
Run Code Online (Sandbox Code Playgroud)

但输出包含版本字段: -

{
  name : 'a',
  description : 'sdmhf',
  version : []
}
Run Code Online (Sandbox Code Playgroud)

上面的代码删除了数据,但我也想从我的集合中删除版本字段.你能告诉我怎么做吗?

mongoose mongodb node.js

2
推荐指数
1
解决办法
3210
查看次数