Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Passport.js错误调试(';分派%s%s';,req.method,req.url);_Node.js_Express_Passport.js - Fatal编程技术网

Node.js Passport.js错误调试(';分派%s%s';,req.method,req.url);

Node.js Passport.js错误调试(';分派%s%s';,req.method,req.url);,node.js,express,passport.js,Node.js,Express,Passport.js,尝试将passport.js用于linkedin oauth协议(passport-linkedin-oauth2),我面临以下问题:在运行“节点服务器”时,出现以下错误: PATH/node_modules/express/lib/router/index.js:139 debug('dispatching %s %s', req.method, req.url); TypeError: Cannot read property 'method' of undefined 这是我

尝试将passport.js用于linkedin oauth协议(passport-linkedin-oauth2),我面临以下问题:在运行“节点服务器”时,出现以下错误:

  PATH/node_modules/express/lib/router/index.js:139
  debug('dispatching %s %s', req.method, req.url);
  TypeError: Cannot read property 'method' of undefined
这是我的server.js文件:

const express = require('express');
const bodyParser = require("body-parser");
const path = require('path');
const passport = require('passport');
const session = require("express-session");
const app = new express();
const os = require('os');
const keys = require('./keys.js');
const listrategy = require('passport-linkedin-oauth2').Strategy;
require('events').EventEmitter.defaultMaxListeners = 15;
const PORT = process.env.PORT || 4000;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static("public"));

const INDEX = path.join(__dirname, 'index.html');
const server = app().get('/',(req, res) => res.sendFile(INDEX))

passport.use(
    new listrategy (
        {
      clientID:  keys.linkedin.clientID,
      clientSecret: keys.linkedin.clientSecret,
      callbackURL: "/auth/linkedin/callback",
      scope: ['r_emailaddress', 'r_liteprofile','w_member_social'],
            state:true
    },function (accessToken,refreshToken,profile,done) {
        process.nextTick(function () {
            console.log('profile',profile);
    return done(null, profile);
  });
    })
);

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.findById(id, function(err, user) {
    done(err, user);
  });
});

app.use(session({resave: false, saveUninitialized: true, secret: 'recudorPegarevAecirP', cookie: { maxAge: 60000 }}));
app.use(passport.initialize());
app.use(passport.session());

app.listen(PORT);
我有一个有效的linkedin密码和ID。 我猜我的声明顺序有问题,或者语法使用不当。然而,我不知道是什么。你能帮忙吗


非常感谢。

您正试图将路由器作为路由器()导出到其他文件中的某个位置,因此出现了此错误

为什么不使用类似的库?@RemisaYousefvand这正是我使用的库