DevOps

Deploy Oracle JET Web App on Application Container Cloud

There’s a few examples on the net about how to deploy a JET app to Application Container Cloud. All of these seem to either create an express app and then add oracle code to it later (eliminating the benefit of using grunt serve) or taking the compiled web folder and putting it into a new express application (making your devops or build automation slightly more painful). Let me show you an alternative.

Add the following to server.js in the root directory.

var http = require('http')
var url = require('url')
var fs = require('fs')
var path = require('path')
var baseDirectory = __dirname + '/web'

var port = process.env.PORT || 8000;

http.createServer(function (request, response) {
	try {
		var requestUrl = url.parse(request.url)
		if (requestUrl.pathname == '/') requestUrl.pathname = '/index.html';
  	// need to use path.normalize so people can't access directories underneath baseDirectory
   	var fsPath = baseDirectory+path.normalize(requestUrl.pathname)

  	response.writeHead(200)
  	var fileStream = fs.createReadStream(fsPath)
   		fileStream.pipe(response)
   		fileStream.on('error',function(e) {
    	response.writeHead(404)     // assume the file doesn't exist
    	response.end()
  	})
 	} catch(e) {
 		response.writeHead(500)
   	response.end()     // end the response so browsers don't hang
   	console.log(e.stack)
 	}
}).listen(port)

This uses the basic http module in Node to create a very simple http server to serve our JET code from the web directory. If you run this using node server.js you should see your node app running, just like if you used grunt serve

You will also need to create a manifest.json file (and optional deployment.json file) to ensure ACC understands your request. The manifest file should look something like this:

{
	"runtime" : {
		"majorVersion": "0.12"
	},
	"command" : "node server.js",
	"release" : {},
	"notes" : "Notes"
}

Now just upload this to ACC (use github.com/Joelith/acc-deploy to make life easier for yourself).

This approach means you can continue to run grunt serve locally as part of your build process and you can still use the same app folder to deploy to ACC.

Advertisements
Technical

Oracle Label Security Part 3: Adding a UI

If you’ve been following along in our series of Oracle Label Security posts (Part 1, Part 2) you should now have a table of ‘documents’ that depending on the users permission will return different sets of documents. In this post we’re going to add a UI so that we can see how Label Security makes application development easier by freeing us from having to worry about security in the application. We won’t actually be doing any database work (that’s been done in the previous posts) and will just focus on getting a simple UI up. You could use any language to build this UI as long as it can connect to the Oracle database (generally through ODBC), which is pretty much of all of them. For this example we are going to build a NodeJs application with a Bootstrap UI. It will be a good demonstration of how to connect NodeJs and the Oracle database together.

The completed application is available on GitHub: https://github.com/Joelith/SecDocNode. Read on to see how it’s built

Continue reading