节点js停止处理来自角度的多个api请求并在重新启动节点应用程序后工作
Posted
技术标签:
【中文标题】节点js停止处理来自角度的多个api请求并在重新启动节点应用程序后工作【英文标题】:node js stops working on multiple api request from angular and working after restarting the node app 【发布时间】:2021-04-01 16:09:02 【问题描述】:我正在使用 node express js 和 angular js 开发一个应用程序。我的角度应用程序在每次路由或按钮单击时从节点 js 应用程序服务器发出 api 请求,单个组件或按钮单击也可能向节点 js 应用程序请求多个 api。在多次请求后,数据加载刚刚停止,我没有得到结果。还会获取 304 和 204 等状态码。
请查看我的 api 代码并订阅服务代码。
constroller.js ///表达js
getList: async (req, res) =>
try
const result = await getList(); //from service.js (an sql query)
var serviceCalls = result[0][0];
return res.set('Content-Type': 'application/json').status(200).json(
success: 1,
message: 'Successfully Data Fetched',
data: serviceCalls
);
catch(e)
return res.json(
success: 0,
message: 'No Data Fetched' + ' ' + e.message,
data:
);
,
getDetails: async (req, res) =>
try
const id = req.query.id
const result = await getDetails(id); //from service.js (an sql query)
var serviceCalls = result[0][0];
return res.set('Content-Type': 'application/json').status(200).json(
success: 1,
message: 'Successfully Data Fetched',
data: serviceCalls
);
catch(e)
return res.json(
success: 0,
message: text:'No Data Fetched ', errMsg: e.message,
data:
);
,
getTroubles: async (req, res) =>
try
const id = req.query.id
const result = await getTroubles(id); //from service.js (an sql query)
var complaintData = result[0][0];
return res.set('Content-Type': 'application/json').status(200).json(
success: 1,
message: 'Successfully Data Fetched',
data: complaintData
);
catch(e)
return res.json(
success: 0,
message: 'No Data Fetched',
data: []
);
,
getLogs: async (req, res) =>
try
const id = req.query.id
const result = await getLogs(id); //from service.js (an sql query)
var feedbackData = result[0][0];
return res.set('Content-Type': 'application/json').status(200).json(
success: 1,
message: 'Successfully Data Fetched',
data: logs
);
catch(e)
return res.json(
success: 0,
message: text:'No Data Fetched ', errMsg: e.message,
data: []
);
,
routes //node js express js app.js
app.use('/serviceCall', serviceCallRoute);
服务呼叫路由
router.get("/getList", getList);
router.get("/getDetails", getDetails);
router.get("/getTroubles", getTroubles);
router.get("/getLogs", getLogs);
角度订阅 api
getServiceCalls()
return this.http.get(url + 'serviceCall/getList',this.httpOptions)
.pipe(
map((res: IServiceCall) =>
return res;
),
catchError(errorRes =>
return throwError(errorRes);
)
);
getServiceCallDetails(id):Observable<IServiceCall>
const params = new HttpParams().set('id', id);
const headers = new HttpHeaders( 'Content-Type': 'application/json')
return this.http.get(url + 'serviceCall/getDetails',headers:headers,params: params)
.pipe(
map((res: IServiceCall) =>
return res;
),
catchError(errorRes =>
return throwError(errorRes);
)
);
getServiceCallTroubles(id)
const params = new HttpParams().set('id', id);
const headers = new HttpHeaders( 'Content-Type': 'application/json')
return this.http.get<IServiceCallTroubles>(url + 'serviceCall/getTroubles',headers:headers,params: params)
.pipe(
map((res: IServiceCallTroubles) =>
return res;
),
catchError(errorRes =>
return throwError(errorRes);
)
);
getServiceCallLogs(id):Observable<IServiceCallLogs>
const params = new HttpParams().set('id', id);
const headers = new HttpHeaders( 'Content-Type': 'application/json')
return this.http.get<IServiceCallLogs>(url + 'serviceCall/getLogs',headers:headers,params: params)
.pipe(
map((res: IServiceCallLogs) =>
return res;
),
catchError(errorRes =>
return throwError(errorRes);
)
);
【问题讨论】:
【参考方案1】:express js 运行良好。数据库连接限制错误。
数据库连接限制设置为 10。因此,在 10 次 api 请求和 sql 查询之后。 db 连接断开。
【讨论】:
以上是关于节点js停止处理来自角度的多个api请求并在重新启动节点应用程序后工作的主要内容,如果未能解决你的问题,请参考以下文章