大佬教程收集整理的这篇文章主要介绍了在heroku上部署node.js应用程序成功但不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我遵循了“Heroku上的Node.js入门”指南[2]中的建议.当我在本地使用节点index.js运行应用程序时,我能够访问@R_489_10107@:// localhost:8080 / index.jade上的应用程序,但是,当我尝试在@R_489_10107@:// immoNow上的heroku上访问它时. herokuapp.com:8080/index.jade它会给我一个ERR_CONNECTION_REFUSED @R_489_10107@错误代码.
我如何部署我的应用:
> git commit -am“进行了更改”//提交更改
> git push origin master //推送到git
> heroku创建//创建heroku应用程序
> git push heroku master //推送到heroku
> heroku ps:scale web = 1 //开始工作
我的node.js服务器:
#!/usr/bin/env node var @R_489_10107@ = require('@R_489_10107@'),jade = require('jade'),static = require('node-static'),jadeRe = /\.jade$/,path = process.argv.slice(2)[0],fileServer = new static.Server(path || '.') @R_489_10107@.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
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('/*',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'); }
以上是大佬教程为你收集整理的在heroku上部署node.js应用程序成功但不起作用全部内容,希望文章能够帮你解决在heroku上部署node.js应用程序成功但不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。