pagespace

APIs

  1. Middleware API
  2. Plugin API

Middleware API

var pagesapce = require('pagespace');

pagespace.getViewEngine()

Returns the instance of the Pagespace view engine.

var viewEngine = pagespace.getViewEngine();
app.engine('hbs', viewEngine);

pagespace.getViewDir()

Returns the Pagespace view directory. Use this as Express view config

app.set('views', [ pagespace.getViewDir(), 'other/dirs' ]);

pagespace.getDefaultTemplateDir()

Returns the default, example template directory, use this for a quick start

app.set('views', [ pagespace.getViewDir(), pagespace.getDefaultTemplateDir() ]);

pagespace.init(opts)

Returns initialized middleware ready to use with Express

app.use(pagespace.init(opts));

opts.db

MongoDB connection string. Required

opts.dbOptions

See Mongoose connection options

opts.logger

A custom Bunyan logger. Overrides the default logger.

opts.logLevel

The log level to use with the default logger. Not relevant if using a custom logger. Defaults to info.

opts.mediaDir

Directory where media uploads are stored. Defaults to [baseDir]/media-uploads

opts.commonViewLocals

Locals that should be made available for every Handlebars template

opts.locale

BCP47 Language tag to use with Format.JS Handlebars helpers, which may be used in templates.

opts.cacheOpts

Live plugin results are cached per include. Internally Pagespace uses Cacheman for this. By default these are cached in memory, but you can uses an alternative Cacheman engine implementation such as Redis. See Cacheman options

pagespace.ready(callback)

Fires a node style callback when Pagespace is ready (it will be ready shortly after the Express server has started. Alternatively, this method returns a Promise.

pagespace.ready(function(err) {
    if(err) {
        console.error(err);
    } else {
        console.log('Pagespace ready');
    }
});

or

pagespace.ready().then(function() {
    console.log('Pagespace ready');
}).catch(function() {
    console.error(err);
});

pagesapce.stop()

Forcefully stop the Pagespace middleware from processing requests. This is useful for tests, but not usually necessary to call.

pagesapce.stop()

Plugin API

When authoring Pagespace plugins, a utility API is available on the pagespace global object

pagespace.getModel(modelNAme)

Get a Mongoose model to interact with the database

pagespace.getModel('Page');

pagespace.logger

A Bunyan logger object to log with