You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
808 B

/**
* directusResponseHandler
*
* handle response from directus, for http of fastify
*
* @author Björn Hase <me@herr-hase.wtf>
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
*
*/
const directusResponseHandler = {
single(entity, response) {
// if data not exists or data is empty redirect to 404
if (!entity.data || entity.data.length === 0) {
return response.redirect('/404')
}
// getting single
entity.data = entity.data[0]
// adding default template for pages
if (!entity.data.template) {
entity.data.template = 'default'
}
response.locals.page = entity
}
}
export default directusResponseHandler