我有一个主要是Angular的MEAN堆栈应用程序,我在节点端有一个API,它有一个端点供我验证JSON Web令牌。但是出于某种原因,我检查网络下的开发控制台并看到api被访问,但是在永远服用之后(我认为它超时)我从服务器获得了503。
Angular :
var verifyToken = function() {
return $http.get('/oauth/verify', {
headers: {
Authorization: 'Bearer ' + getToken()
}
}).success(function(data, status, headers) {
console.log('VERIFY STATUS' + status);
console.log('VERIFY HEADERS' + headers("Authorization"));
});
};
API路线:
var express = require('express');
var router = express.Router();
var jwt = require('express-jwt');
var auth = jwt({
secret: 'gas', // process.env.JWT_SECRET
userProperty: 'payload'
});
var ctrlOauth = require('../controllers/oauth');
var ctrlCallback = require('../controllers/callback');
var ctrlVerify = require('../controllers/verifyJWT');
// authentication
router.get('/oauth', ctrlOauth.login);
router.get('/callback', ctrlCallback.callback);
// verify JWT
router.get('/verify', auth, ctrlVerify.verify);
module.exports = router;
verifyJWT.js :
module.exports.verify = function(req, res) {
return true;
};
这个想法是使用express-jwt
中间件来验证路由。问题是当我发出角度get
请求时,它会超时。再一次,这是在Heroku上托管的。有任何想法吗?谢谢!
响应标头:
Cache-Control:no-cache, no-store
Connection:keep-alive
Content-Length:484
Content-Type:text/html; charset=utf-8
Date:Wed, 26 Oct 2016 21:57:27 GMT
Server:Cowboy
回复:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
html, body, iframe { margin: 0; padding: 0; height: 100%; }
iframe { display: block; width: 100%; border: none; }
</style>
<title>Application Error</title>
</head>
<body>
<iframe src="//s3.amazonaws.com/heroku_pages/error.html">
<p>Application Error</p>
</iframe>
</body>
</html>