我正在尝试托管在OpenShift上使用socket.io的nodeJS应用程序。我在openshift上创建了应用程序,使用git clone
来获取回购 - 然后我编辑server.js
看起来像这样:
#!/bin/env node
var express = require('express');
var app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
var osipaddress = process.env.OPENSHIFT_NODEJS_IP;
var osport = process.env.OPENSHIFT_NODEJS_PORT;
app.set('port', osport || 8000);
app.set('ipaddress', osipaddress);
/*var pf = require('policyfile').createServer();
pf.listen(10843, function(){
console.log(':3 yay')
});*/
server.listen(app.get('port'), app.get('ipaddress'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
app.use(express.static(__dirname + '/'));
app.get('/', function (req, res) {
res.sendfile(__dirname + '/Startup.html');
});
io.configure(function() {
io.set('transports', ['websocket','xhr-polling']);
io.set('flash policy port', 10843);
//io.set('log level', 1);
});
io.sockets.on('connection', function (socket) {
socket.on('message', function (data) {
console.log(data);
});
});
然后我使用git commit
/ git push
进行更改。
当我运行rhc tail testapp
时,输出不会产生任何错误:
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/highline-1.6.21/lib/highline/system_extensions.rb:230: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
DEBUG: Running node-supervisor with
DEBUG: program 'server.js'
DEBUG: --watch '/var/lib/openshift/53a2e6275973ca689c000060/app-root/data/.nodewatch'
DEBUG: --ignore 'undefined'
DEBUG: --extensions 'node|js|coffee'
DEBUG: --exec 'node'
DEBUG: Starting child process with 'node server.js'
DEBUG: Watching directory '/var/lib/openshift/53a2e6275973ca689c000060/app-root/data/.nodewatch' for changes.
info: socket.io started
Express server listening on port 8080
但是,当我访问该网站时 - 我仍然会看到最初的欢迎页面(好像我没有推送任何代码) - http://testapp-eamonbenproject.rhcloud.com/
有什么想法吗?由于我没有真正得到错误,我不知道从哪里开始。
答案 0 :(得分:2)
Startup.html
需要命名为index.html
才能使openshift正常工作。