This article will guide you in how to serve static resources when running Oracle REST Data Services (ORDS) in Standalone Mode.
Before you go any further you’ll need to download and install Oracle REST Data Services. Click here for instructions on how to get ORDS up and running in under 5 minutes.
ORDS 3.0.1 and later support configuring a document root that can be used to serve arbitrary static resources.
The location of the document root is configured using the --document-root
option of the standalone
command. For example to point the document root at /var/www/html
do the following
|
|
You do not need to specify the --document-root
argument
on every startup, the value is remembered and will continue to be used on each subsequent launch of standalone mode.
The location pointed to by --document-root
must exist and must be readable by the process running ORDS.
If you prefer, you can use the default document root location, which is:
|
|
where ${config.dir}
is the location of the ORDS configuration folder. You can check the value of this setting by doing:
|
|
The location must exist and must be readable by the process runnning ORDS. The doc_root
sub-folder of the standalone
folder is not created automatically, you will need to create it manually.
Let’s work through an example of serving static resources using Standalone Mode.
For this example we will assume the following:
localhost
and listening on port 8080
./var/www/html
.To make this a bit more interesting we’re going to use the Bower package manager to install all the CSS etc that the pages will depend on. To install Bower you will first need to install Node Package Manager (NPM), if you do not have it installed already. The install instructions vary depending on operating system.
If you are using a Mac and have Homebrew installed it’s as simple as:
|
|
Once you have npm
installed you can install Bower:
|
|
Yes, we did just use a package manager to install two more package managers!
Let’s create a basic project. We’re going to skip plenty of steps in a modern front-end build workflow, for instance we’re not going to build our front-end assets using Gulp or Grunt, just to prevent this tutorial getting too long.
First let’s create a folder to work in:
|
|
Now we are ready to start creating our static html. We’re going to build our example using Bootstrap, so we’ll use Bower to install that:
|
|
This will create a folder named bower_components
in / var/www/html/example
where the bootstrap assets will be stored, the example/
folder will now look like this:
|
|
Next we can create our sample HTML page, create the following in your favorite text editor and save as /var/www/html/example/index.html
|
|
Time to test this out, if you haven’t already, start ORDS :
|
|
This will start ORDS and cause it launch in Standalone Mode. Look for the following text in the console output to ensure ORDS is serving static content from the correct folder:
|
|
If you don’t see this message then ensure you’ve completed the steps above to configure the document root.
Now type the following URL in your browser:
|
|
A page similar to the following should be displayed:
As the example above shows if a folder contains a file named index.html
or index.htm
ORDS will serve it when the URL of the folder is requested.
Simiarly if a file with a .html
or .htm
extension
exists within the document root then that file can
be accessed without it’s file extension. Let’s try this out, create the following in your favorite text editor and save as /var/www/html/example/pretty-nice.html
|
|
Now try the URL of the resource in your browser:
|
|
A page similar to the following should be displayed:
Note how the URL lacks the .html
extension.
The support for welcome files and serving HTML resources without their extension helps mimic how static resources are typically served in production environments.