Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-prismic

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-prismic

Prismic.io support for Prismic.io

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

express-prismic

Prismic.io support for ExpressJS

npm version

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 = require('express-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.init({
  apiEndPoint: "https://your-repo-name.prismic.io", // Mandatory
  linkResolver: function(doc) { // Mandatory
    return false;
  },
  accessToken: "xxx" // Optional
});

Usage

You can then create a Prismic context in your routes if you need to query your repository:

app.route('/').get(function(req, res) {
  var p = prismic.withContext(req,res); // This will retrieve the API object asynchronously (using a promise)
  p.getByUID('page', 'get-started', function (err, document) {
    res.render('index-prismic', {
      document: document
    });
  });
});

Several helper functions are available to query your repository. The most flexible is the query function:

  var p = prismic.withContext(req,res); // This will retrieve the API object asynchronously (using a promise)
  p.query(prismic.Predicate.fulltext('document', term), {
    page: 2,
    pageSize: 10
  }, function (err, results) {
    [...]
  });

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

Keywords

FAQs

Package last updated on 18 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc