RESTApp resources
Static resources are stored in the /resource
folder.
AppResource
The AppResource utility is used to access resources within a RESTApp. RESTApp resources are ONLY open to its enclosing RESTApp, i.e. its content cannot be extracted or downloaded elsewhere.
// retrieve an instance of the appResource utility
var appResource = require('appResource');
Resources can be accessed in three different ways, where pathToResource
is the path to the file in the resource folder.
appResource.getContent(pathToResource)
Returns the resource as a UTF-8 based string.
appResource.getNode(pathToResource)
Returns the resource as a JCR Node (sv:image or sv:file).
appResource.getInputStream(pathToResource)
Returns the resource as a java.io.BufferedInputStream.
(function() {
'use strict';
var
router = require('router'),
appResource = require('appResource'),
logUtil = require('LogUtil'),
propertyUtil = require('PropertyUtil');
router.get('/text', function(req, res) {
var message = appResource.getContent('message.txt');
res.json({message: message});
});
router.get('/pdf', function(req, res) {
var pdf = appResource.getNode('pdf/info.pdf');
logUtil.info(propertyUtil.getString(pdf, 'jcr:primaryType')); // sv:file
res.sendFile(pdf);
});
}());