Problem
You run node . to start your Loopback application; it starts fine, but on your first request to the API you get a database connection error:
{ Error: Pool is closed. at Pool.getConnection (/home/ubuntu/code/lb3/node_modules/mysql/lib/Pool.js:25:15) at MySQL.executeSQL (/home/ubuntu/code/cumberland/lb3/node_modules/loopback-connector-mysql/lib/mysql.js:239:12) at /home/ubuntu/code/lb3/node_modules/loopback-connector-mysql/node_modules/loopback-connector/lib/sql.js:418:10
Shoot.
Solution
You could be disconnecting from the database in one of your startup scripts (under the boot directory). In my case, I had a script to create tables for Loopback's Role, User, AccessToken's etc and at the end I had the offending line:
module.exports = function(app)I took out that line and all is well.
{
var mysqlDs = app.dataSources.mysqlDs;
var lbTables = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
mysqlDs.automigrate(lbTables, function(er) {
if (er) throw er;
console.log('Loopback tables [' - lbTables - '] created in ', mysqlDs.adapter.name);
mysqlDs.disconnect(); });
}
I love you, I really do.
ReplyDelete