迁移到 CloudFlare 后 Chrome 中的无效重定向错误
Invalid redirect error in Chrome after migrating to CloudFlare
我的站点 www.exampartner.in 在 EC2 实例上运行,使用 NodeJS 连接到我在 bigrock.in 上购买的域。为了使用 SSL,我迁移到了 CloudFlare,但是自从我迁移到 CloudFlare 之后,我的网站就出现了问题。主要问题是我在将 https 重定向设置为页面规则后在 javascript、徽标和 ham pic 上遇到的无效重定向错误。然后我禁用它并尝试通过 HTTP 加载这些资源,但它仍然失败。现在我也禁用了 SSL,页面似乎可以正常工作。我已附上 screenshot 以供参考。请帮忙。谢谢你。
这是我的 routes.js:
var express = require('express');
var router = express.Router();
var passport = require('passport');
router.get('/login', function (req, res, next) {
res.render('login', { message: req.flash('loginMessage'), user: req.user });
});
router.get('/', function (req, res) {
res.render('mainpage', { user: req.user });
});
router.get('/signup', function (req, res, next) {
res.render('signup', { message: req.flash('signupMessage'), user: req.user });
});
// process the login form
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
// app.post('/signup', do all our passport stuff here);
router.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/signup', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
// =====================================
// PROFILE 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)
router.get('/profile', isLoggedIn, function (req, res) {
res.render('profile', {
user: req.user // get the user out of session and pass to template
});
});
// =====================================
// LOGOUT ==============================
// =====================================
router.get('/logout', function (req, res) {
req.logout();
res.redirect('/');
});
// };
// route middleware to make sure a user is logged in
function isLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't logged redirect them to the home page
res.redirect('/');
}
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
router.get('/bitsat', function (req, res) {
res.render('bitsat', { user: req.user });
})
router.get('/aieee', function (req, res) {
res.render('aieee', { user: req.user });
})
router.get('/ip', function (req, res) {
res.render('ip', { user: req.user });
})
router.get('/jeemain', function (req, res) {
res.render('jeemain', { user: req.user });
})
router.get('/jeeadvanced', function (req, res) {
res.render('jeeadvanced', { user: req.user });
})
router.get('/jeemain/:year', function (req, res) {
res.render(__dirname + '/views/jee_main/' + req.params.year, { user: req.user });
});
router.get('/jeemain/:year/:paper', function (req, res) {
var filename = req.params.paper.substr(0, 2) + 'April' + req.params.year
var mor = req.params.paper.indexOf('Morning')
var eve = req.params.paper.indexOf('Evening')
if (mor !== -1) {
filename = filename + req.params.paper.substr(mor, req.params.paper.length)
}
if (eve !== -1) {
filename = filename + req.params.paper.substr(eve, req.params.paper.length);
}
res.download(__dirname + '/downloads/jee_main/' + req.params.year + '/' + filename + '.pdf')
});
router.get('/bitsat/:op', function (req, res) {
res.render(__dirname + '/views/bitsat/' + req.params.op, { user: req.user });
});
router.get('/bitsat/:op/:year', function (req, res) {
res.download(__dirname + '/downloads/bitsat/' + req.params.op + '/' + req.params.year + '.pdf')
});
module.exports = router;
编辑: 为了使用 Cloudflare 的严格 SSL,您需要在服务器上安装 SSL 证书。 Lets Encrypt provides free SSL certificates that have to be renewed every 90 days. If the process seems difficult, you can use Zero SSL 这使得从 lets encrypt 获取证书以及更新现有证书变得容易。
您必须设置 express 才能处理 https request/response。 Node.js 应用程序需要 ssl 证书和密钥。
const express = require('express')
const fs = require('fs')
const https = require('https')
const app = express()
https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app)
.listen(process.env.PORT || 3000, function () {
console.log('"App Listening at port:" + port')
})
我的站点 www.exampartner.in 在 EC2 实例上运行,使用 NodeJS 连接到我在 bigrock.in 上购买的域。为了使用 SSL,我迁移到了 CloudFlare,但是自从我迁移到 CloudFlare 之后,我的网站就出现了问题。主要问题是我在将 https 重定向设置为页面规则后在 javascript、徽标和 ham pic 上遇到的无效重定向错误。然后我禁用它并尝试通过 HTTP 加载这些资源,但它仍然失败。现在我也禁用了 SSL,页面似乎可以正常工作。我已附上 screenshot 以供参考。请帮忙。谢谢你。 这是我的 routes.js:
var express = require('express');
var router = express.Router();
var passport = require('passport');
router.get('/login', function (req, res, next) {
res.render('login', { message: req.flash('loginMessage'), user: req.user });
});
router.get('/', function (req, res) {
res.render('mainpage', { user: req.user });
});
router.get('/signup', function (req, res, next) {
res.render('signup', { message: req.flash('signupMessage'), user: req.user });
});
// process the login form
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
// app.post('/signup', do all our passport stuff here);
router.post('/signup', passport.authenticate('local-signup', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/signup', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
// =====================================
// PROFILE 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)
router.get('/profile', isLoggedIn, function (req, res) {
res.render('profile', {
user: req.user // get the user out of session and pass to template
});
});
// =====================================
// LOGOUT ==============================
// =====================================
router.get('/logout', function (req, res) {
req.logout();
res.redirect('/');
});
// };
// route middleware to make sure a user is logged in
function isLoggedIn(req, res, next) {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't logged redirect them to the home page
res.redirect('/');
}
router.post('/login', passport.authenticate('local-login', {
successRedirect: '/profile', // redirect to the secure profile section
failureRedirect: '/login', // redirect back to the signup page if there is an error
failureFlash: true // allow flash messages
}));
router.get('/bitsat', function (req, res) {
res.render('bitsat', { user: req.user });
})
router.get('/aieee', function (req, res) {
res.render('aieee', { user: req.user });
})
router.get('/ip', function (req, res) {
res.render('ip', { user: req.user });
})
router.get('/jeemain', function (req, res) {
res.render('jeemain', { user: req.user });
})
router.get('/jeeadvanced', function (req, res) {
res.render('jeeadvanced', { user: req.user });
})
router.get('/jeemain/:year', function (req, res) {
res.render(__dirname + '/views/jee_main/' + req.params.year, { user: req.user });
});
router.get('/jeemain/:year/:paper', function (req, res) {
var filename = req.params.paper.substr(0, 2) + 'April' + req.params.year
var mor = req.params.paper.indexOf('Morning')
var eve = req.params.paper.indexOf('Evening')
if (mor !== -1) {
filename = filename + req.params.paper.substr(mor, req.params.paper.length)
}
if (eve !== -1) {
filename = filename + req.params.paper.substr(eve, req.params.paper.length);
}
res.download(__dirname + '/downloads/jee_main/' + req.params.year + '/' + filename + '.pdf')
});
router.get('/bitsat/:op', function (req, res) {
res.render(__dirname + '/views/bitsat/' + req.params.op, { user: req.user });
});
router.get('/bitsat/:op/:year', function (req, res) {
res.download(__dirname + '/downloads/bitsat/' + req.params.op + '/' + req.params.year + '.pdf')
});
module.exports = router;
编辑: 为了使用 Cloudflare 的严格 SSL,您需要在服务器上安装 SSL 证书。 Lets Encrypt provides free SSL certificates that have to be renewed every 90 days. If the process seems difficult, you can use Zero SSL 这使得从 lets encrypt 获取证书以及更新现有证书变得容易。
您必须设置 express 才能处理 https request/response。 Node.js 应用程序需要 ssl 证书和密钥。
const express = require('express')
const fs = require('fs')
const https = require('https')
const app = express()
https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.cert')
}, app)
.listen(process.env.PORT || 3000, function () {
console.log('"App Listening at port:" + port')
})