应用程序在尝试加载根路径时返回错误

时间:2018-03-02 18:55:39

标签: javascript node.js express

我写了一个简单的javascript文件,它允许我通过Web浏览器查看数据库中的值。它以前工作但现在它返回以下错误:

<?php

// Script to test if the CURL extension is installed on this server

 // Define function to test
    function _is_curl_installed() {
if  (in_array  ('curl', get_loaded_extensions())) {
    return true;
}
else {
    return false;
}
}

// Ouput text to user based on test
 if (_is_curl_installed()) {
    echo "cURL is <span style=\"color:blue\">installed</span> on this server";
  } else {
  echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}
?>

我很确定我没有更改代码或数据库中的任何内容,所以不确定为什么它现在失败了,任何帮助都会非常感激。

以下是代码:

_http_outgoing.js:494
    throw new Error('Can\'t set headers after they are sent.');
    ^

Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:494:11)
    at ServerResponse.setHeader (_http_outgoing.js:501:3)
    at ServerResponse.header (issuesDB/node_modules/express/lib/response.js:767:10)
    at ServerResponse.send (issuesDB/node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (issuesDB/node_modules/express/lib/response.js:267:15)
    at ServerResponse.send (issuesDB/node_modules/express/lib/response.js:158:21)
    at db.all (issuesDB/app.js:23:21)
    at Statement.errBack (issuesDB/node_modules/sqlite3/lib/sqlite3.js:16:21)

1 个答案:

答案 0 :(得分:2)

就像你回复两个回复一样。您错过了return声明。

if (err) return res.status(500).send('Something went wrong, we are working on it');
res.status(200).send({issues: rows});