什么错误在NodeJS
What the error in NodeJS
我的应用程序在NodeJS 0.10运行在我的节点localhost(127.0.0.1)和我的链接不听,和发现OpenShift !但没有运行我的脚本,错误:(http://nodejs2-agenciadreamup.rhcloud.com/),我的GitHub (https://github.com/AlanPS/StreamBrasil)…帮助我!!
我代码:var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = __dirname + '/aula.mp4';
var stat = fs.statSync(path);
var total = stat.size;
if (req.headers['range']) {
var range = req.headers.range;
var parts = range.replace(/bytes=/, "").split("-");
var partialstart = parts[0];
var partialend = parts[1];
var start = parseInt(partialstart, 10);
var end = partialend ? parseInt(partialend, 10) : total-1;
var chunksize = (end-start)+1;
console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
var file = fs.createReadStream(path, {start: start, end: end});
res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': 'video/mp4' });
file.pipe(res);
} else {
console.log('ALL: ' + total);
res.writeHead(200, { 'Content-Length': total, 'Content-Type': 'video/mp4' });
fs.createReadStream(path).pipe(res);
}
}).listen(8080, "127.0.0.1");
console.log('Server running at 127.0.0.1:8080');
看起来服务器正在使用127.0.0.1:8080,而不是openshift的情况。修改如下:
var http = require('http'),
fs = require('fs'),
util = require('util');
// if on OpenShift, use OpenShift ip/port, else use your local ip/port
var ipAddress = process.env.OPENSHIFT_INTERNAL_IP || process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_INTERNAL_IP || process.env.OPENSHIFT_NODEJS_PORT || 8080;
http.createServer(function (req, res) {
// This part of code is unchanged, so it's removed to simplify
// the answer
}).listen(port, ipAddress); // <<<<< use variables set above
console.log('Server running at ' + ipAddress + ":" + port);
为了将服务器连接到OpenShift的路由系统,您需要包含对系统提供的虚拟IP地址(process.env.OPENSHIFT_NODEJS_IP
)的检查。
如果你的应用程序失败,或者无法建立连接,路由系统会响应503
。
相关文章:
- 与域在同一台计算机上运行的NODEJS服务器的CORS错误
- nodejs和heroku:抛出新错误(setHeader()需要“名称”和“值”');
- NodeJS错误-Can't在发送标头后设置标头
- NodeJS服务器在检索部分时返回505/404错误
- Javascript返回错误的Date值(NodeJS)
- NodeJS用Multer上传图片;错误:意外字段“”;
- 具有默认参数值的 ES6 类构造函数上的 NodeJS 错误
- 处理 nodejs 错误并提供不同自定义消息详细信息的最佳方法
- NodeJS 错误堆栈未定义
- nodejs 错误:Socket.ondata 上的解析错误
- 获取 nodejs 错误的行号
- NodeJS 错误与 connect-busboy,“类型错误:无法调用未定义的方法'on'”
- Nodejs:错误:找不到模块'html'
- NodeJS-错误:找不到指定的过程.bcrypt_lib.node
- NodeJS错误处理-使用错误代码或子类
- Nodejs错误未定义不是函数
- NodeJs错误v-host中间件
- 回调(xml-stream)中的Nodejs错误处理
- nodejs - 错误:在使用模块 gm 调整图像大小时生成 ENOENT
- Nodejs错误:协议"http:"不受支持的.预计“https:“