Today I tried to host a small Hapijs app in Openshift, as it may be useful for others just documenting here,
Creating new Gear with Nodejs cartridge in Openshift
Test it locally and push it to openshit, enjoy coding.
Creating new Gear with Nodejs cartridge in Openshift
- Goto https://openshift.redhat.com/app/console/applications
- Click Add application and add nodejs cartridge
- clone the project just created in openshift.
- delete all the files/folders except .openshift folder (note: make sure files deleted in git as well)
- create new hapijs project on the same folder (refer: http://hapijs.com/tutorials)
- npm init
- npm install --save hapi
- create a file called index.js with following content
#!/bin/env node var Hapi = require('hapi'); // Create a server with a host and port var server = new Hapi.Server(); var ipaddress = process.env.OPENSHIFT_NODEJS_IP; var port = process.env.OPENSHIFT_NODEJS_PORT || 8080; if (typeof ipaddress === "undefined") { // Log errors on OpenShift but continue w/ 127.0.0.1 - this allows us to run/test the app locally. console.warn('No OPENSHIFT_NODEJS_IP var, using 127.0.0.1'); ipaddress = "127.0.0.1"; }; server.connection({ host: ipaddress, port: port}); // Add the route server.route({ method: 'GET', path:'/', handler: function (request, reply) { reply.file('Hello World!!!'); } }); // Start the server server.start();