首页 > 解决方案 > 为什么我的快速路由函数不会触发它们的回调函数?

问题描述

我已经通过护照身份验证建立了一些路由,但它们都没有触发他们的回调。路线正在运行,但没有任何内容记录到控制台供我调试。谁能帮我弄清楚为什么?下面是我的 server.js 的一部分

app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cookieParser());


app.use(passport.initialize());
app.use(passport.session());

app.use(cors({
    origin: 'https://localhost:3000',
    methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
    allowedHeaders: "Content-Type,Authorization",
    credentials: true
}));


app.get("/", (req, res) => {
    console.log('Welcome')
});

app.get("/auth/yahoo", passport.authenticate("yahoo"), (req, res) => {
    console.log('Authenticating..')
  });

app.get("/auth/yahoo/redirect",
  passport.authenticate("yahoo", {
      failureRedirect: "/auth/login/failed" 
    }),
    function(req, res) {
        console.log('Redirecting..')
    // Successful authentication, redirect home.
    res.redirect('/profile');
    }
);

app.get("/auth/login/failed", (req, res) => {
    console.log('Authentication Failed')
});

const port = 9000;

const httpsOptions = {
    key: fs.readFileSync('./security/key.pem'),
    cert: fs.readFileSync('./security/cert.pem')
};

const server = https.createServer(httpsOptions, app)
    .listen(port, () => {
        console.log('server running at ' + port)
});

谢谢!

标签: javascriptnode.jsexpresscallbackpassport.js

解决方案


推荐阅读