Ошибка POST http: abc / 404 (не найдено) в angular2 + и nodejs - PullRequest
0 голосов
/ 30 июня 2018

Я делаю запрос http из моего кода angular2+ в базу данных, присутствующую в файле node.js. Вызов ajax из angular2+ попадает в файл controller.js, а затем перенаправляется в файл service.js, который имеет соединение с базой данных:

angular.ts ==> controller.js ==> service.js

Из базы данных файл service.js передает выходные данные в файл controller.js, а затем отвечает на вызов ajax в файл angular.ts:

service.js ==> controller.js ==> angular.ts

Однако я получаю сообщение об ошибке:

POST http://localhost:8096/dashboard/abcEntireSuccess1/ 404 (Not Found)

ОБНОВЛЕНО Не удается получить / панель инструментов / ExperianEntireSuccess1 /

И еще один выпуск -

   UnauthorizedError: No authorization token was found

И еще один выпуск -

После возвращения из обращения в service.js, в котором есть данные, которые я хочу ==> to => controller.js, здесь полученные данные не определены. Как видно ниже -

Выход на Nodejs -

вывод -

service.js

  closed connection
  yessss [ RowDataPacket { ....

controller.js

  we are coming back to controller undefined

  some error occured of abcEntireSuccess1

Весь мой код: ОБНОВЛЕНО

abc.component.ts

viewAbcEntireSuccess1() {


var url = config.url;
var port = config.port;


this.http.post("http://" + url + ":" + port + "/dashboard  
  /abcEntireSuccess1/", this.emptyObj
  , { headers: new Headers({ 'Authorization': 'Bearer ' + 
    localStorage.getItem('Token') }) })
  .map(resultConnection => this.resultConnection = 
    resultConnection.json(), )
   .subscribe((res: Response) => {

     this.records = res;

     this.resultConnectionlength = this.resultConnection.length;

   });

 }

abc.controller.js

  router.post('/experianEntireSuccess1',experianEntireSuccess1);
  module.exports = router;


    function abcEntireSuccess1(req, res) {


    dashboardService.abcEntireSuccess1(req.body)
      .then(function (result) {
        console.log("we are coming back to controller",result)
        if (result.length > 0) {
            console.log("we get data in node of abcEntireSuccess1 :: 
         " + Object.values(result));
            console.log(result.length + " record found  ");
            res.send(result);
           } 
         else {
            result=[];
            res.send(result);
         }
     })
     .catch(function (err) {
        res.status(400).send(err);
        console.log("some error occured of abcEntireSuccess1");
      });
      }

abc.service.js

  async function abcEntireSuccess1() {
  console.log("function called")
   const db = new Database();
   await db.query(`select * from TRANSACTION_PAYLOAD where INTERFACE_NAME
    = 'Abc' AND (STATUS ='SUCCESS_RESPONSE')`
    ).then(rows => {

    console.log("closed connection");

    console.log("yessss",rows)
    return rows;

     });
    };

   class Database {
   constructor() {

      this.connection = mysql.createConnection({
        host: "127.0.0.1",
        user: "abc",
        password: "abc",
        database: "DB"
      });

    }


  query(sql, args) {
    console.log("sql is", sql)
    return new Promise((resolve, reject) => {
        this.connection.query(sql, (err, rows) => {
            console.log("connection function called")
            if (err) {
                console.log("error is", err)
                return reject(err);
            }

            console.log("rows are",rows);
            resolve(rows);
        });
       });
     }
   close() {

     console.log("calling connection close")
     return new Promise((resolve, reject) => {
        console.log("called connection close")
        this.connection.end(err => {
            if (err){
                return reject(err);
            }

            resolve();
        });
     });
     }
     }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...