openshift node.js Cannot Get /

让人想犯罪 __ 提交于 2020-01-03 05:06:31

问题


I have this simple node.js static file server:

var express = require('express');   
var app = express();   
app.use(express.cookieParser());  
app.use(express.bodyParser());  
app.use(express.methodOverride());  
app.use(express.session({ secret: "secret" }));  
app.use(express.static(process.env.OPENSHIFT_REPO_DIR + '/public' ));  

var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";  
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;  
app.listen(port, ipaddress);  

When I publish to OpenShift (no errors in the terminal) and navigate to the site, I see Cannot GET /

I have index.html in my public folder, along with some css and JavaScript.

Any idea what I'm doing wrong?


回答1:


Here it is: Hey, did you make sure to commit the public folder?




回答2:


You need the load the routes.

var express = require('express');
var app = express();

app.get('/', function(req, res){
  res.send('hello world');
});

app.listen(3000);

You are also not loading any views.

Here's the documentation of express: http://expressjs.com/guide.html



来源:https://stackoverflow.com/questions/21790598/openshift-node-js-cannot-get

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