0

node-express と mysql(およびクライアント側のバックボーン js)を使用して appfog でホストされているアプリがあります。localhost では正常に動作しますが、アプリを展開すると、しばらくの間は正常に動作し、しばらくするとクラッシュします (コンソールで再起動した場合) appfog admin の同じことが起こります) これは接続 mysql のコードの一部です

var mysql = require("mysql")

var env = JSON.parse(process.env.VCAP_SERVICES);
var creds = env['mysql-5.1'][0]['credentials'];
console.log(creds)

var client = mysql.createConnection({
  host: creds.host || "localhost",
  user: creds.user,
  password: creds.password,
  port: creds.port,
  database: "savelinks"
});

app.js のコード

var express  = require("express");
var path = require("path");
var port = 9000;
var request = require('request');
var cheerio = require('cheerio');

var app = module.exports = express();

console.log(process.env.VCAP_SERVICES)

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);  
  app.use(express.static(path.join(__dirname, 'public')));
 });

 var server  = require("http").createServer(app)
  app.get("/", function(req,res){

    res.render("index");
 });

 /*
  * GET ALL LINKS ON LOAD PAGE
 */
 app.get("/links", function(req, res){

     links = db.client.query("SELECT * FROM links ORDER BY created DESC", function(err, result){
      if(!err){
         res.json(result)
      }
   });
});
// more routers
 app.listen(process.env.VCAP_APP_PORT || port, function(){
    console.log("server run in port " + port)
 });

これは、アプリの霧が示すログです

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: Connection lost: The server closed the connection.
    at Protocol.end (/mnt/var/vcap.local/dea/apps/savelinks-0-ca19c96d36d4701debe7fe46752707c5/app/node_modules/mysql/lib/protocol/Protocol.js:73:13)
    at Socket.onend (stream.js:66:10)
    at Socket.EventEmitter.emit (events.js:126:20)
    at TCP.onread (net.js:417:51)

この問題を解決するためのアイデアはありますか?

4

1 に答える 1