【发布时间】:2016-01-17 01:24:49
【问题描述】:
我正在尝试了解 JWT 以及它们如何与 Node 和 Express .js 一起使用。我有这个中间件尝试使用令牌对用户进行身份验证:
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() })
即使路径是正确的(我什至尝试使用 path.join(__dirname + '/pubblica/inserisciutente.html) 并得到相同的结果),在访问 url 时我只是得到一个空白页面(甚至节点 conde里面)我也设置了:app.use(express.static('/pubblica')) PS如果我尝试用 res.send('Some stuff') 替换 res.sendFile(..) 我可以在页面上正确查看它。我做错了什么?
【问题讨论】:
-
请正确缩进您的代码。缩进不当的代码很难理解。
标签: javascript node.js express