Node.Js - Ошибка: соединение потеряно: сервер закрыл соединение - PullRequest
0 голосов
/ 12 марта 2020

Две недели go Я развернул свое первое приложение как часть моей новой работы (Woo Hoo! :)), но каждую ночь с тех пор, как я его развернул - приложение вылетает. Серверная часть была построена с Node.js, и я использую XAMPP и MYSQL для запуска базы данных. Так что это ошибка, которую я постоянно получаю: enter image description here

Я искал решение и нашел этот код:

var connection;
function handleDisconnect() {
    connection = mysql.createConnection(con); // Recreate the connection, since
                                                    // the old one cannot be reused.

    connection.connect(function(err) {              // The server is either down
      if(err) {                                     // or restarting (takes a while sometimes).
        // console.log('error when connecting to db:', err);
        setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
      }                                     // to avoid a hot loop, and to allow our node script to
    });                                     // process asynchronous requests in the meantime.
                                            // If you're also serving http, display a 503 error.
    connection.on('error', function(err) {
    //   console.log('db error', err);
      if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
        handleDisconnect();                         // lost due to either server restart, or a
      } else {                                      // connnection idle timeout (the wait_timeout
        throw err;                                  // server variable configures this)
      }
    });
  }

  handleDisconnect();

Я вставил этот код после функция createConnection:

var con = mysql.createConnection({
    host: "EXAMPLE FOR STUCK OVER FLOW",
    user: "EXAMPLE FOR STUCK OVER FLOW",
    password: "EXAMPLE FOR STUCK OVER FLOW",
    database: "EXAMPLE FOR STUCK OVER FLOW"
});

Буду очень признателен за ваш совет!

Спасибо !!!

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