我正在节点服务器上使用Express并尝试发送签名的cookie,
var express = require('express');
var app = express();
var cookieParser = require('cookie-parser');
app.use(cookieParser("secret"));
app.get('/', function(req, res){
res.cookie('cookie1', 'This is my first cooke', {maxAge: 1000*60*60*24*7, httpOnly: true});
res.send({'status':'Cookie has been set'});
});
一切看起来不错,但仍然出现以下错误: 犯错//抛出非MySQL错误 ^
错误:签名的cookie需要cookieParser(“ secret”) 在ServerResponse.res.cookie(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/express/lib/response.js:833:11) 在Query._callback(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/app/router/index_seco.js:85:17) 在Query.Sequence.end(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24) 在Query._handleFinalResultPacket(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)处 在Query.EofPacket(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/protocol/sequences/Query.js:123:8) 在Protocol._parsePacket(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/protocol/Protocol.js:279:23) 在Parser.write(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/protocol/Parser.js:76:12) 在Protocol.write(/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/protocol/Protocol.js:39:16) 在套接字。 (/home/trd/TRD/new-rapi/676cb539092d21127ded33478d1073ab6886fc33/node_modules/mysql/lib/Connection.js:103:28) 在Socket.emit(events.js:189:13) 在addChunk(_stream_visible.js:284:12) 在readAddChunk(_stream_visible.js:265:11) 在Socket.Readable.push(_stream_visible.js:220:10) 在TCP.onStreamRead [阅读时](internal / stream_base_commons.js:94:17)