DEV Community

Cover image for Hosting static websites on Openshift
Austin Cunningham
Austin Cunningham

Posted on • Updated on

Hosting static websites on Openshift

I had a site that I wished to host on Openshift.

Express.js

Because the Node run time was supported I decide to host using a simple Express.js server. I had a git repository with an index.html file in the root. I ran npm init and excepted all the defaults.

That’s all I need to setup a Node app, I then proceed to add Express.js to it

npm install --save express
Enter fullscreen mode Exit fullscreen mode

I also added a start script to the package.json

"scripts": {    
           "test": "echo \"Error: no test specified\" && exit 1",
           "start": "node index.js"  
},
Enter fullscreen mode Exit fullscreen mode

Added index.js Express server

var express = require('express');
var app = express(); 
// serves files from the root directory
app.use(express.static('./'));
app.listen(8080, function () {    
  console.log('Listening at http://localhost:8080');  
});
Enter fullscreen mode Exit fullscreen mode

I committed the changes to git remote repo. I created a new project in Openshift , browsed the catalog and selected Node.

I entered an Application name and an the Git repository where my index.html was and click create. The Node version does’t overly matter for this small app.

The project proceeded to build and pull the git repo. You can check the progress on the Overview for the project

Once the build was finished I was able to access my static site from the url provide by Openshift.

Nginx

It turns out that Openshift as of May 2018 now has Nginx in the catalog. So the route to hosting static websites is a little easier. You sill need an git repo with a index.html in the root directory but you can get your site up with zero code. Create a new project and from the catalog select Nginx.

The steps are much the same as deploying the Node app above i.e. Add application name and git repository, once the build is complete your site is up on the Route-External traffic.

Myblog

Top comments (0)