express-prismic
Prismic.io support for ExpressJS
This is a set of helpers to use Prismic.io in an Express application. If you're starting from scratch, our NodeJS SDK is a good base.
Configuration
After including express-prismic
in your package.json
, simply import the prismic object:
var prismic = Prismic;
The Prismic object is extended from the Javascript Kit, so any attribute of the official kit, for example Predicates
, is also available in the object exposed by express-prismic.
It needs to be initialized with your configuration:
prismic;
Usage
You can then create a Prismic context in your routes if you need to query your repository:
app;
Several helper functions are available to query your repository. The most flexible is the query
function:
var p = prismic; // This will retrieve the API object asynchronously (using a promise) p;
Previews
You can preview any document including drafts in your production site, securely. All you have to do is:
- Include this route:
app.route('/preview').get(prismic.preview);
- Configure the URL to that preview route in the settings of your repository
- Make sure that the Prismic Toolbar is included in your views