Node.js app on openshift

允我心安 提交于 2019-12-12 15:18:14

问题


I have issues with an express application that works fine locally

node server.js

but has this error on openshift:

...

    Uninitialized option at server.js:104:9 events.js:72
    throw er; // Unhandled 'error' event
          ^
    Error: listen EACCES
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1020:19)
...

I have understood that this would be an issue with my .createServer().listen implementation. My code is:

var express = require('express');
var path = require('path');
....//I cut code from here..Bunch of middleware..
var https = require('https');
var http = require('http');

....//My routes were here...
var app = express();

//HTTP
var server_port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var server_ip_address = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
http.createServer(app).listen(server_port);

var ssl = {
key: fs.readFileSync('keys/key.pem'),
cert: fs.readFileSync('keys/cert.pem')
};

https.createServer(ssl, app).listen(443);

I'd also like to have working ssl, but i couldn't find info on that.


回答1:


server = require('http').createServer(app)

port = process.env.OPENSHIFT_NODEJS_PORT || 8080  
ip = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";

server.listen(port, ip);

Has always worked for me in the past. I'm not entirely confident that rearranging the stuff you have to match (since yours is almost identical) but its how I have it working in my current nodejs app. Also, for further context can you paste in the lines from Uninitialized option at server.js:104:9 events.js:72, if you've done so already can you mark them? from what I can see your stuff should work.



来源:https://stackoverflow.com/questions/25271618/node-js-app-on-openshift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!