PassportJS Node.js请求https

时间:2019-01-21 03:26:27

标签: javascript node.js passport.js

在我的应用程序nodejs中插入ssl后,用于身份验证层的passportjs会通知用户在执行AJAX POST并且页面经过window.location.replace()之后,未在应用程序中对用户进行身份验证。

我已经看过文档,没有找到问题的参考,使用hpp的localhost我没有这个问题。

有人会帮忙吗?

app.js

var express           = require('express');
var session           = require('express-session');
var cookieParser      = require('cookie-parser');
var bodyParser        = require('body-parser');
var logger            = require('morgan');
var path              = require('path');
var fileUpload        = require('express-fileupload');
var https             = require('https');
var fs                = require('fs');
var httpsOptions = {
    key: fs.readFileSync(path.join("key.pem")),
    cert: fs.readFileSync(path.join("cert.pem"))
};
var app               = express();
var expressValidator  = require('express-validator');
var passport          = require('passport');
var flash             = require('connect-flash');

// - Cria rotas
var routes            = require('./routes/index');
var usuarios          = require('./routes/usuario');
var motorista         = require('./routes/motorista');
var login             = require('./routes/login');
var aluno             = require('./routes/aluno');
var contrato          = require('./routes/contrato');
var boleto            = require('./routes/boleto');
var pessoa            = require('./routes/pessoa');

require('./security/autenticacao')(passport);

app.use(logger('dev'));
app.use(expressValidator());
app.use(cookieParser());
app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(session({
    secret: 'reis&turlwaysrunning',
    resave: true,
    saveUninitialized: true
 } ));
app.use(logErrors);
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
app.use(function (req, res, next) {
    res.locals.login = req.user;
    next();
});
app.use(fileUpload());
// Atriui rotas
app.use('/home', routes);
app.use('/usuarios', usuarios);
app.use('/alunos', aluno);
app.use('/motoristas', motorista);
app.use('/contratos', contrato);
app.use('/login', login);
app.use('/boletos', boleto);
app.use('/pessoas', pessoa);

https.createServer(httpsOptions, app).listen(8080);

app.set('port', process.env.PORT || 21108);
app.listen(app.get('port')); 


function logErrors (err, req, res, next) {
    console.error('Troxa: ' + err.stack)
    next(err)
  }


module.exports = app;

0 个答案:

没有答案