在heroku上部署node.js应用程序成功,但不起作用

我有一个非常简单,直接的node.js应用程序[1]我想部署在heroku上。 尽pipe我能够部署它,但是页面无法在浏览器中访问。

我遵循了“Heroku上的Node.js入门”指南中的build议[2]。 当我在本地使用node index.js运行应用程序时,我可以通过http://localhost:8080/index.jade访问应用程序,但是当我尝试在http://immonow.herokuapp.com:8080/index.jade heroku上访问应用程序时http://immonow.herokuapp.com:8080/index.jade它会给我一个ERR_CONNECTION_REFUSED HTTP错误代码。

我如何部署我的应用程序:

  1. git commit -am "made changes" //提交更改
  2. git push origin master // push to git
  3. heroku create //创buildheroku应用程序
  4. git push heroku master //推到heroku
  5. heroku ps:scale web=1 //开始工作

我的node.js服务器:

 #!/usr/bin/env node var http = require('http') , jade = require('jade') , static = require('node-static') , jadeRe = /\.jade$/ , path = process.argv.slice(2)[0] , fileServer = new static.Server(path || '.') http.createServer(function (req, res) { if (req.url.match(jadeRe)) { res.writeHead(200, {'Content-Type': 'text/html'}) res.end(jade.renderFile('.' + req.url, { filename: '.' + req.url.replace(jadeRe, '') })) } else { req.addListener('end', function () { fileServer.serve(req, res) }).resume() } }).listen(8080) 

任何帮助,将不胜感激。

[1] https://github.com/takahser/immonow

[2] https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction

由于我无法使用http包来工作,我决定使用express。 至于港口,我不得不这样做

 var port = process.env.PORT || 3000; app.listen(port); 

为了得到它的工作[1]。

这是我的全部工作服务器:

 /** * Module dependencies. */ var express = require('express'); // Path to our public directory var pub = __dirname + '/public'; // setup middleware var app = express(); app.use(express.static(pub)); app.use("/css", express.static(__dirname + '/css')); app.use("/font", express.static(__dirname + '/font')); app.use("/img", express.static(__dirname + '/img')); app.use("/js", express.static(__dirname + '/js')); app.use("/video", express.static(__dirname + '/video')); // Set our default template engine to "jade" // which prevents the need for extensions // (although you can still mix and match) app.set('view engine', 'jade'); app.get('/', function(req, res){ res.render('index'); }); app.get('/*', function(req, res){ console.log(req.url.replace("/","")); res.render(req.url.replace("/","")); }); // change this to a better error handler in your code // sending stacktrace to users in production is not good app.use(function(err, req, res, next) { res.send(err.stack); }); /* istanbul ignore next */ if (!module.parent) { var port = process.env.PORT || 3000; app.listen(port); console.log('Express started on port 3000'); } 

[1]请参阅: Heroku雪松堆栈上的Node.js端口问题