我在NodeJS 0.10中的应用程序正在我的Node localhost(127.0.0.1)中运行而我的链接不听,而且还有Discovery 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');
答案 0 :(得分:0)
看起来服务器正在使用127.0.0.1:8080,而openhift则不然。这是改变:
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);
答案 1 :(得分:0)