0
我有以下功能位於CR-route.js這可確保用戶在繼續之前驗證,並顯示他的名字爲什麼我的應用程序無法到達console.log?
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('/');
});
};
我打電話從位於home.js以下模塊這條路線:
require('./routes/home')(app);
但我甲肝:
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;
};
然後我發出以下調用從app.js文件這個模塊儘管我能夠成功加載home.js,但它仍然不能訪問它內部的get方法。
我該如何解決這個問題?