Reputation: 3
I have application on Openshift (Node.js 0.10, MongoDB 2.4)
I have followed instructions here
developers.openshift.com/en/getting-started-debian-ubuntu.html
and I have modified successfully my app.
When I run it from this URL http://kunsento-mbtest1.rhcloud.com/
it works fine. You can try it.
If I try to use this URL http://kunsento-mbtest1.rhcloud.com/index.html
I get "Cannot GET /index.html"
I get the same error if I try to access any other html file in the subdirectories.
Please could you advice how to solve it?
Thank you
p.s. I have found similar ticket here;
openshift node.js Cannot Get /
but I do not understand how to apply the solution "did you make sure to commit the public folder?"
Upvotes: 0
Views: 3539
Reputation: 1400
When you check the server.js
that comes with the OpenShift's nodejs cartridge, you'll see there that there is the /
route defined to serve the index file:
self.routes['/'] = function(req, res)
{
res.setHeader('Content-Type', 'text/html');
res.send(self.cache_get('index.html') );
};
...therefore you will get the index file, when visiting your domain.
Routes are typically created for any other functionality, that should be provided by web applications.
If you'd like to serve static files, you can create a public directory similarly as in the example you have linked.
Supposing you are using the server.js
that comes with the nodejs cartridge, you can simply add self.app.use(express.static(__dirname + '/public'));
into the initializeServer
function to have the content of the public
directory served. Here is how the whole block may look like, for clarity:
/**
* Initialize the server (express) and create the routes and register
* the handlers.
*/
self.initializeServer = function() {
self.createRoutes();
self.app = express.createServer();
// Add handlers for the app (from the routes).
for (var r in self.routes) {
self.app.get(r, self.routes[r]);
}
// static files
self.app.use(express.static(__dirname + '/public'));
};
You may also want to look on this for more details.
Upvotes: 1