@bcgov/carbone-copy-api
Express API for calling Carbone with a file caching layer.
Last updated 4 months ago by parcjason .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bcgov/carbone-copy-api 
SYNC missed versions from official npm registry.

carbone-copy-api

Express library that provides and interface for generating documents from templates and data. It provides a local file storage cache that means callers do not have to upload the template for each render. Callers should should store cache keys/hashes and check if templates exist before generation.
This is a wrapper around carbone, please refer to their documentation for more detail. The API follows their recommendations.

important

This library will require LibreOffice installed. It requires LibreOffice to do pdf generation.

See image: alpine-node-libreoffice.

usage

install

npm i @bcgov/carbone-copy-api

configuration

There are several configuration variables that allow for customization.

Config Var ENV Var Notes
fileUploadsDir CACHE_DIR This is the root location to read/write files. Error will be thrown if directory does not exist and cannot be created. Default is operating system temp file location.
formFieldName UPLOAD_FIELD_NAME Field name for multipart form data upload when uploading templates via /template api. Default is 'template'
maxFileSize UPLOAD_FILE_SIZE Limit size of template files. Uses the bytes library for parsing values. Default is '25MB'
maxFileCount UPLOAD_FILE_COUNT Limit the number of files uploaded per call. Default is 1, not recommended to use any other value.
startCarbone START_CARBONE If true, then the carbone converter will be started on application start. This will ensure that the first call to /render will not incur the overhead of starting the converter. Default is 'true'

pass in options

const carboneCopyApi = require('@bcgov/carbone-copy-api');

const options = {
   fileUploadsDir: '/tmp/my-application-holding/files',
   formFieldName: 'files',
   maxFileSize: '50MB',
   maxFileCount: 1,
   startCarbone: true
};

carboneCopyApi.init(options);

use environment variables

export CACHE_DIR = '/tmp/my-application-holding/files'
export UPLOAD_FIELD_NAME = 'files'
export UPLOAD_FILE_SIZE = '50MB'
export UPLOAD_FILE_COUNT = 1
export START_CARBONE = 'true'

...
const carboneCopyApi = require('@bcgov/carbone-copy-api');
carboneCopyApi.init();

default

# defaults are:
#
#   fileUploadsDir: '/tmp/carbone-files',
#   formFieldName: 'template',
#   maxFileSize: '25MB',
#   maxFileCount: 1,
#   ccApiBasePath: '/',
#   startCarbone: true
#

const carboneCopyApi = require('@bcgov/carbone-copy-api');
carboneCopyApi.init();

NOTE: maxFileSize uses the bytes library for parsing values.

mount the routes

The mount function accepts an express app, a path and configuration options (optional).

The following example will mount the carbone-copy-api at the root of the server.

const carboneCopyApi = require('@bcgov/carbone-copy-api');

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
...
carboneCopyApi.mount(app, '/');

The following example will mount the carbone-copy-api to an alternate path on the server.

const carboneCopyApi = require('@bcgov/carbone-copy-api');

const options = {
   fileUploadsDir: '/tmp/my-application-holding/files',
   formFieldName: 'template',
   maxFileSize: '50MB',
   maxFileCount: 1,
   startCarbone: true
};

const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
...
carboneCopyApi.mount(app, '/api/cc/v1', options);

review api at /docs

Once mounted, view the Open API spec at /docs.

Current Tags

  • 1.0.3                                ...           latest (4 months ago)

4 Versions

  • 1.0.3                                ...           4 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.1                                ...           5 months ago
  • 1.0.0                                ...           5 months ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (12)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |