我想了解JWT以及它们如何与Node和Express .js一起工作。我有这样的中间件,试图用令牌来验证用户身份:ExpressJs res.sendFile在中间件后不工作
app.use(function(req, res, next) {
if(req.headers.cookie) {
var autenticazione = req.headers.cookie.toString().substring(10)
autenticazione = autenticazione.substring(0, autenticazione.length - 3)
console.log(autenticazione)
jwt.verify(autenticazione, app.get('superSegreto'), function(err) {
if (err) {
res.send('authentication failed!')
} else {
// if authentication works!
next() } })
} else {
console.log('errore')} })
这是代码为我的保护网址:
app.get('/miao', function (req, res) {
res.sendFile(__dirname + '/pubblica/inserisciutente.html')
res.end() })
即使路径是正确的(我甚至与路径尝试。加入(__ dirname +'/pubblica/inserisciutente.html)并得到相同的结果),当访问网址我刚刚得到一个空白页(甚至节点康德里面)我也设置:app.use(express.static('/ pubblica'))PS如果我尝试用res.send('Some stuff')替换res.sendFile(..),我可以在页面上正确地查看它。我究竟做错了什么?
请正确缩进您的代码。很难遵循不正确缩进的代码。 – jfriend00