feat(credentials): allow setting of space id and tokens via query string
This commit is contained in:
committed by
Benedikt Rötsch
parent
9806d494dc
commit
926b59aaaa
15
app.js
15
app.js
@@ -37,6 +37,17 @@ app.use(function (req, res, next) {
|
||||
res.locals.query = req.query
|
||||
res.locals.currentPath = req.path
|
||||
console.log(req.path)
|
||||
|
||||
// Allow setting of credentials via query parameters
|
||||
const { space_id, preview_access_token, delivery_access_token } = req.query
|
||||
if (space_id && preview_access_token && delivery_access_token) { // eslint-disable-line camelcase
|
||||
const settings = {space: space_id, cda: delivery_access_token, cpa: preview_access_token}
|
||||
res.cookie('universitySettings', settings, { maxAge: 900000, httpOnly: true })
|
||||
initClient(settings)
|
||||
} else {
|
||||
initClient(req.cookies.universitySettings)
|
||||
}
|
||||
|
||||
next()
|
||||
})
|
||||
|
||||
@@ -65,8 +76,4 @@ app.use(function (err, req, res, next) {
|
||||
res.render('error')
|
||||
})
|
||||
|
||||
// app.use()
|
||||
// init the contentful client
|
||||
initClient()
|
||||
|
||||
module.exports = app
|
||||
|
||||
@@ -3,9 +3,21 @@ const { createClient } = require('contentful')
|
||||
let cdaClient = null
|
||||
let cpaClient = null
|
||||
|
||||
exports.initClient = (config = {space: process.env.CF_SPACE, accessToken: process.env.CF_ACCESS_TOKEN}) => {
|
||||
cdaClient = createClient(config)
|
||||
cpaClient = createClient({space: process.env.CF_SPACE, accessToken: process.env.CF_PREVIEW_ACCESS_TOKEN, host: 'preview.contentful.com'})
|
||||
exports.initClient = (options) => {
|
||||
const config = options || {
|
||||
space: process.env.CF_SPACE,
|
||||
cda: process.env.CF_ACCESS_TOKEN,
|
||||
cpa: process.env.CF_PREVIEW_ACCESS_TOKEN
|
||||
}
|
||||
cdaClient = createClient({
|
||||
space: config.space,
|
||||
accessToken: config.cda
|
||||
})
|
||||
cpaClient = createClient({
|
||||
space: config.space,
|
||||
accessToken: config.cpa,
|
||||
host: 'preview.contentful.com'
|
||||
})
|
||||
}
|
||||
|
||||
exports.getCourses = (locale = 'en-US', api = `cda`) => {
|
||||
|
||||
Reference in New Issue
Block a user