Skip to content

Commit

Permalink
Merge pull request #37 from cdt105/master
Browse files Browse the repository at this point in the history
Update to match the Kentico Kontent configuration and allow for preview mode
  • Loading branch information
Domitnator authored Jul 15, 2021
2 parents d487f11 + b9c71b3 commit ae1b344
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ npm i rxjs --save (because this is a peer dependency of the Kentico Kontent Deli
- Add `kentico-kontent-nuxt-module` to `modules` section of `nuxt.config.js`

```js

/*
** Nuxt.js modules
*/
Expand All @@ -32,7 +31,9 @@ npm i rxjs --save (because this is a peer dependency of the Kentico Kontent Deli
projectId: 'xxxx-xxx-xxxx-xxxx-xxxxx',
enableAdvancedLogging: false,
previewApiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
enablePreviewMode: true,
globalQueryConfig: {
usePreviewMode: true, // Queries the Delivery Preview API.
},
baseUrl: 'https://custom.uri/api/KenticoKontentProxy',
securedApiKey: 'xxx',
enableSecuredMode: true
Expand Down
4 changes: 3 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module.exports = function kenticokontent (moduleOptions) {
projectId: process.env.KENTICOKONTENT_PROJECTID || '',
previewApiKey: process.env.KENTICOKONTENT_PREVIEWAPIKEY || null,
enableAdvancedLogging: process.env.KENTICOKONTENT_ENABLEADVANCEDLOGGING || false,
enablePreviewMode: process.env.KENTICOKONTENT_ENABLEPREVIEWMODE || false,
globalQueryConfig: {
usePreviewMode: process.env.KENTICOKONTENT_ENABLEPREVIEWMODE || false
},
defaultLanguage: process.env.KENTICOKONTENT_DEFAULTLANGUAGE || null,
retryAttempts: process.env.KENTICOKONTENT_RETRYATTEMPTS || null,
baseUrl: process.env.KENTICOKONTENT_BASEURL || null,
Expand Down
18 changes: 10 additions & 8 deletions lib/templates/plugin.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import CacheService from '../services/CacheService'
export default (ctx, inject) => {
// Create new delivery client Instance
let settings = JSON.parse('KENTICOOPTIONS')

// Adds customHeaders if not already set
if(!settings.globalQueryConfig.customHeaders)
{
settings.globalQueryConfig.customHeaders = []
}

// Add tracking header
settings = Object.assign({}, settings, {
globalQueryConfig: {
customHeaders: [
{ header: 'X-KC-SOURCE', value: 'kentico-kontent-nuxt-module' }
]
}
})
// Adds X-KC-SOURCE to identify this module is in use
settings.globalQueryConfig.customHeaders.push(
{ header: 'X-KC-SOURCE', value: 'kentico-kontent-nuxt-module' }
);

const deliveryClient = new DeliveryClient(settings)

Expand Down

0 comments on commit ae1b344

Please sign in to comment.