2013-10-01 6 views
0

appfog에서 node-express 및 mysql (및 클라이언트 측에서 백본 js)을 사용하여 앱을 호스팅하고 있지만 로컬 호스트에서는 잘 작동하지만 배포 할 때 잠시 동안 제대로 작동합니다. 한 번 충돌 (내가 appfog 관리자의 콘솔에서 다시 시작하면 같은 일이 발생) 후 이 연결 MySQL을위한 코드의 일부는appfog에서 애플 리케이션 크래시가 노드 js 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) 

이 문제를 해결하는 방법에 대한 아이디어가 있으십니까?

답변

0

필자는 개인 개발 컴퓨터가 아닌 프로덕션에서 동일한 종류의 문제를 겪었습니다. 내 노드 서버는 node-mysql을 사용하여 Ubuntu VM에 연결합니다. 내 노드 서버가 충돌하고 다시 시작되며 하루 종일 같은 종류의 오류가 표시됩니다.

다음 방법은 노드 MySQL의 GitHub의 페이지에서 설명하는 나를 위해 문제를 해결하기 위해 노력 :

https://github.com/felixge/node-mysql#server-disconnects