问题
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