我有一个 api 一个域和其他域中的所有其他 api。所以在 SprtsAppConstatnts.js 中,我对所有域进行了硬编码。当我打印然后 formatUrl ---> 存在于 document.js 它打印哪个是正确的域然后 formatUrl ---> http://players.com/run/kit/?id=0900000000009009093292390230923其中 URL ===> 在文件 SportsResUtility.js 中打印出错误的域 URL ===> http://sports.com/tes/run/kit/?id=090000000009009093292390230923因为它exports.DATA_DNS_NAME = "http://sports.com";从文件 SprtsAppConstatnts.js 中获取硬编码值不确定如何在 SportsResUtility.js 中添加代码,以便仅针对此路径添加此域http://players.com我在服务器日志中显示了两个错误。不确定它来自哪个文件。 (node:30332) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
(node:30332) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.有什么方法可以找出它来自哪个文件。我是否需要安装任何其他软件包进行调试。在下面提供我的代码片段和沙箱SprtsAppConstatnts.jsexports.GET_JWT_TOKEN_URL = 'https://credentials.com';exports.DATA_DNS_NAME_CONTENT_CENTRAL = "http://players.com";// "http://usersports.com"; // "http://fddfdfdf.main.com:9080"; // dp-rest-apis-urlexports.DATA_DNS_NAME = "http://sports.com"; // "http://fddfdfdf.main.com:9080"; // dp-rest-apis-urlexports.CUST_MICRO_SVC_DNS_NAME = "http://fddfdfdf.main.com";exports.SERVICE_SERVER_DNS_NAME = 'http://sports.com';exports.REST_API_dfdfdfdf_DNS_NAME = 'https://dfdfdfdf.com';SportsResUtility.jsconst axios = require('axios');const SprtsAppConstatnts = require('../../constants/SprtsAppConstatnts');const credentials = require('../../internals/credentials.json');const authUtil = require('./AuthorizationUtil');module.exports ={ callService : (res, url, uri) => { var formatUrl; if(uri){ formatUrl = uri + url; } else{ formatUrl = SprtsAppConstatnts.DATA_DNS_NAME + url; }
2 回答

九州编程
TA贡献1785条经验 获得超4个赞
(node:30332) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Can't set headers after they are sent.
此错误意味着您send()
根据请求进行操作,然后尝试使用它,就像尚未发送并再次发送一样。
您将变量传递res
到SportsResUtility.callService
您调用的位置res.send()
,并且您也调用res.send()
了document.js
,因此您执行了两次,这是不可能的。
添加回答
举报
0/150
提交
取消