From 170050154b8e83ce4d8d24f1760be5355fd63308 Mon Sep 17 00:00:00 2001 From: Sebastien Renault Date: Thu, 8 Jun 2017 16:49:35 +0200 Subject: [PATCH] Rename config to PrismicConfig --- app.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index 5dfa1bb..330c8cb 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,7 @@ const Prismic = require('prismic-nodejs'); const request = require('request'); const Cookies = require('cookies'); -const config = require('./prismic-configuration'); +const PrismicConfig = require('./prismic-configuration'); const Onboarding = require('./onboarding'); const app = require('./config'); @@ -12,29 +12,28 @@ app.listen(PORT, () => { process.stdout.write(`Point your browser to: http://localhost:${PORT}\n`); }); -// Middleware catch all request, query Prismic API and configure everything for it +// Middleware to inject prismic context app.use((req, res, next) => { - // init prismic context res.locals.ctx = { - endpoint: config.apiEndpoint, - linkResolver: config.linkResolver, + endpoint: PrismicConfig.apiEndpoint, + linkResolver: PrismicConfig.linkResolver, }; - Prismic.api(config.apiEndpoint, { - accessToken: config.accessToken, + + Prismic.api(PrismicConfig.apiEndpoint, { + accessToken: PrismicConfig.accessToken, req, - }) - .then((api) => { + }).then((api) => { req.prismic = { api }; - // continue spreading request next(); - }) - .catch((error) => { - // next with params handle error natively in express + }).catch((error) => { next(error.message); }); }); -// INSERT YOUR ROUTES HERE +/* + * --[ INSERT YOUR ROUTES HERE ]-- + */ + /* * Route with documentation to build your project with prismic */ @@ -47,7 +46,7 @@ app.get('/', (req, res) => { */ app.get('/help', (req, res) => { const repoRegexp = new RegExp('^(https?://([\\-\\w]+)\\.[a-z]+\\.(io|dev))/api$'); - const match = config.apiEndpoint.match(repoRegexp); + const match = PrismicConfig.apiEndpoint.match(repoRegexp); const repoURL = match[1]; const name = match[2]; const host = req.headers.host; @@ -58,11 +57,10 @@ app.get('/help', (req, res) => { /* * Preconfigured prismic preview */ -// preview app.get('/preview', (req, res) => { const token = req.query.token; if (token) { - req.prismic.api.previewSession(token, config.linkResolver, '/') + req.prismic.api.previewSession(token, PrismicConfig.linkResolver, '/') .then((url) => { const cookies = new Cookies(req, res); cookies.set(Prismic.previewCookie, token, { maxAge: 30 * 60 * 1000, path: '/', httpOnly: false });