SORU
28 Mart 2013, PERŞEMBE


Heroku node.js hata (Web süreci başlatmak dolarlık LİMAN içinde 60 saniye bağlayamadı)

İlk node.js benim uygulama (yerel olarak iyi çalışır) var - ama heroku (ilk kez w/ de heroku) dağıtmak için kuramıyorum. Kodu aşağıda. YANİ sadece benim ağ içinde çalışan kod yerel olarak da hiç bir sorunu gösterir yani diyorum ki beni bu kadar kod yazmaya izin vermiyor.

 var http = require('http');
 var fs = require('fs');
 var path = require('path');

 http.createServer(function (request, response) {

    console.log('request starting for ');
    console.log(request);

    var filePath = '.'   request.url;
    if (filePath == './')
        filePath = './index.html';

    console.log(filePath);
    var extname = path.extname(filePath);
    var contentType = 'text/html';
    switch (extname) {
        case '.js':
            contentType = 'text/javascript';
            break;
        case '.css':
            contentType = 'text/css';
            break;
    }

    path.exists(filePath, function(exists) {

        if (exists) {
            fs.readFile(filePath, function(error, content) {
                if (error) {
                    response.writeHead(500);
                    response.end();
                }
                else {
                    response.writeHead(200, { 'Content-Type': contentType });
                    response.end(content, 'utf-8');
                }
            });
        }
        else {
            response.writeHead(404);
            response.end();
        }
    });

 }).listen(5000);

 console.log('Server running at http://127.0.0.1:5000/');

Herhangi bir fikir ?

CEVAP
28 Mart 2013, PERŞEMBE


Heroku dinamik olarak uygulama bir port atar, sabit sayıda bağlantı noktası ayarlayın. Heroku env port ekler, oradan indirebiliriz. Senin bu dinle anahtarı:

.listen(process.env.PORT || 5000)

Bu şekilde hala yerel olarak test ettiğinizde port 5000 dinlemek, ama aynı zamanda Heroku üzerinde çalışacak.

Node.js here Heroku belgeleri kontrol edebilirsiniz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • katherine gomez

    katherine go

    1 Aralık 2011
  • TechnoBuffalo

    TechnoBuffal

    8 HAZİRAN 2007
  • thewinekone

    thewinekone

    17 Aralık 2005