节点 js 停止处理来自 angular 的多个 api 请求并在重新启动节点应用程序后工作

node js stops working on multiple api request from angular and working after restarting the node app

我正在用 node express js 和 angular js 开发一个应用程序。我的 angular 应用程序在每次路由或按钮单击时从节点 js 应用程序服务器发出 api 请求,而且单个组件或按钮单击可能会向节点 js 应用程序请求多个 api。多次请求后,数据加载刚刚停止,我没有得到结果。还获取状态代码,如 304 和 204。

请查看我的api代码并订阅服务代码。

constroller.js ///express 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);

serviceCallRoute

router.get("/getList", getList);
router.get("/getDetails", getDetails);
router.get("/getTroubles", getTroubles);
router.get("/getLogs", getLogs);

angular subscribe to 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);
        })
      );
  }

express js 运行良好。是数据库连接限制错误。

数据库连接限制设置为 10。因此,在 10 个 api 请求和 sql 查询之后。数据库连接断开。