简体   繁体   English

为什么我的应用程序未到达console.log?

[英]why isn't my application reaching the console.log?

I have the following function located in cr-route.js that makes sure that the user is authenticated before proceeding and displays his name 我在cr-route.js中具有以下功能,该功能可确保在继续操作之前验证用户身份并显示其姓名

module.exports = function (app, passport) {

    // =====================================
    // HOME PAGE (with login links) ========
    // =====================================
    app.get('/', function (req, res) {
        res.render('index.ejs'); // load the index.ejs file
    });

    // =====================================
    // LOGIN ===============================
    // =====================================
    // show the login form
    app.route('/login')
        .get(function (req, res) {

            // render the page and pass in any flash data if it exists
            res.render('login.ejs', {
                message: req.flash('loginMessage')
            });
        })

        // process the login form
        .post(passport.authenticate('local-login', {
                successRedirect: '/home', // redirect to the secure profile section
                failureRedirect: '/', // redirect back to the signup page if there is an error
                failureFlash: true // allow flash messages
            }),
            function (req, res) {
                console.log("hello");


                if (req.body.remember) {
                    req.session.cookie.maxAge = 1000 * 60 * 3;
                } else {
                    req.session.cookie.expires = false;
                }
                res.redirect('/');
            });

    // =====================================
    // SIGNUP ==============================
    // =====================================
    // show the signup form
    app.get('/signup', function (req, res) {
        // render the page and pass in any flash data if it exists
        res.render('signup.ejs', {message: req.flash('signupMessage')});
    });

    // process the signup form
    app.post('/signup', passport.authenticate('local-signup', {
        successRedirect: '/home', // redirect to the secure home section
        failureRedirect: '/', // redirect back to the signup page if there is an error
        failureFlash: true // allow flash messages
    }));

    // =====================================
    // Home SECTION =========================
    // =====================================
    // we will want this protected so you have to be logged in to visit
    // we will use route middleware to verify this (the isLoggedIn function)
    app.get('/home', isLoggedIn, function (req, res) {
        res.render('home.ejs', {
            title: 'C',
            user: req.user // get the user out of session and pass to template
        });
    });

    // =====================================
    // LOGOUT ==============================
    // =====================================
    app.get('/logout', function (req, res) {
        req.logout();
        res.redirect('/');
    });
};

I am calling this route from the following module located at home.js: 我从位于home.js的以下模块调用此路由:

var express = require('express');
var router = express.Router();
var url = require('url');
var passport = require('passport');


    module.exports = function (app) {
        require('../app/cr-route')(app, passport);
        app.get('/home', function (req, res, next) {
            var queryData = url.parse(req.url, true).query;
            console.log('im in'); //not displaying

        });
        return router;
    };

then I am calling this module from app.js file by issuing the following: 然后我通过发出以下命令从app.js文件调用此模块:

require('./routes/home')(app);

But I have a feeling that although I am able to successfully load the home.js, it's still not accessing the get method inside of it. 但是我有一种感觉,尽管我能够成功加载home.js,但仍然无法访问其中的get方法。

How can I fix this problem? 我该如何解决这个问题?

You have the same route, /home , defined in cr-route.js and home.js . 您在cr-route.jshome.js定义了相同的路由/home I assume the one in home.js never get called because it was already handled in cr-route.js 我认为home.js中的home.js永远不会被调用,因为它已经在cr-route.js处理了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的数组没有更新,即使它在我 console.log() 时更新 - Why isn't my array updating even though it updates when I console.log() 为什么console.log在以下Express代码中不起作用? - Why isn't console.log working in the following Express code? 为什么 webpack 不保留 console.log 语句? - Why isn't webpack retaining console.log statements? 为什么按钮不起作用? (检查console.log) - Why isn't button working? (checking console.log) 为什么在等待之后不调用 console.log? - Why isn't console.log called after an await? 控制台日志 ({value}) 与 console.log(value) 不同 - Console log ({value}) isn't the same as console.log(value) 为什么我的功能没有达到目标? - Why isn't my function reaching this point? 为什么 console.log 不在 VS 代码终端中打印任何内容并打开命令提示符? - Why console.log isn't printing anything in VS code terminal and opening the command prompt? 为什么我的 React 组件不会在 foreach 中呈现我想要的内容,但会使用 console.log 记录数组? - Why doesn't my React component renders what I want in a foreach, but will console.log the array? 为什么当我按开始时我的 console.log 消息不显示? - Why doesn't my console.log message show when I press Start?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM