error..name:MongoNetworkError ...消息:'无法连接到服务器

时间:2018-06-27 10:53:57

标签: node.js mongodb mongoose mlab

运行服务器时出现此错误... 我在password.js下的代码是

      const JwtStrategy = require('passport-jwt').Strategy;
      const ExtractJwt = require('passport-jwt').ExtractJwt;
      const mongoose = require('mongoose');
      const User = mongoose.model('users');
      const keys = require('../config/keys');

      const opts = {};
      opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
      opts.secretOrKey = keys.secretOrKey;
      module.exports = passport => {
        passport.use(
        new JwtStrategy(opts , (jwt_payload, done) =>{
          User.findById(jwt_payload.id)
          .then(user =>{
            if(user){
              return done(null,user);
            }
            return done(null,false);
          }
        )
        .catch(err =>console.log(err));
      }));
    };

在运行时显示此错误

0 个答案:

没有答案