我收到以下错误
RangeError: Maximum call stack size exceeded
at TCP.hasOwnProperty (native)
at _hasBinary (/usr/local/lib/node_modules/socket.io/node_modules/has-binary/index.js:49:45)
app.js
var express = require('express');
var app = express();
// var responseHandlerRouter = require('./routes/responseHandlerRouter.js');
routes = require('./routes');
var server = app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
io = require('/usr/local/lib/node_modules/socket.io').listen(server);
app.use('/', routes(io));
route.js
var express = require('express');
var router = express.Router();
module.exports = function (io) {
// all of this router's configurations
router.post('/paymentResponse', function (req, res, next) {
io.sockets.emit('notification', res);
res.end('well finally I am here');
});
return router;
}
的index.html
<!doctype html>
<html>
<head>
<script src="http://127.0.0.1:3000/socket.io/socket.io.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
<script>
var socket = io.connect('http://localhost:3000');
socket.on('notification', function (data) {
console.log(data);
});
</script>
</head>
<body>
<ul id='messages'></ul>
</body>
</html>
当我发布到网址http://localhost:3000/paymentResponse时,我在运行nodejs服务器的终端中收到此错误。
答案 0 :(得分:0)
您正在序列化整个响应对象(您的res
参数),这可能会因循环引用而导致堆栈溢出。不要序列化整个响应对象,但要挑选你需要的属性。