【发布时间】:2018-09-06 20:02:25
【问题描述】:
(节点:7636)UnhandledPromiseRejectionWarning:错误:发送后无法设置标头。
在 validateHeader (_http_outgoing.js:491:11)
在 ServerResponse.setHeader (_http_outgoing.js:498:3)
在 ServerResponse.header (C:\Users\username\path\Express\node_modules\express\lib\response.js:767:10)
在 ServerResponse.send (C:\Users\username\path\Express\node_modules\express\lib\response.js:170:12)
在 ServerResponse.json (C:\Users\username\path\Express\node_modules\express\lib\response.js:267:15)
在 ServerResponse.send (C:\Users\username\path\Express\node_modules\express\lib\response.js:158:21)
在 body.rows.forEach (C:\Users\username\path\Express\app.js:41:15)
在 Array.forEach ()
在 db.list.then (C:\Users\username\path\Express\app.js:40:19)
在
(节点:7636)UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。 (拒绝编号:2)
查询代码如下:
app.get("/api/customers", (req, res, next) =>{
res.header("Access-Control-Allow-Origin", "http://localhost");
res.header("Access-Control-Allow-Methods", "GET, POST");
res.writeHead(200, {'Content-Type': 'application/json'});
db.list({ include_docs: true }).then((body) => {
body.rows.forEach((doc) => {
res.send(doc.doc);
});
});
});
我想使用 angularjs 在 html 页面上显示数据。
任何帮助我都会非常感激。
【问题讨论】: