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.

46 lines
1.1 KiB

import path from 'path'
import PageStore from './../stores/page.js'
import directusResponseHandler from './../handlers/directusResponse.js'
/**
* page
*
* @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
*
*/
export default async function(fastify, opts) {
/**
* prehandler for all routes
*
* @param {[type]} request
* @param {[type]} reponse
* @param {Function} done
* @return {[type]}
*/
fastify.addHook('preHandler', async function(request, response) {
const pageStore = new PageStore()
// getting single page
const page = await pageStore.findOneByPermalink(request.url)
directusResponseHandler.single(page, response)
})
/**
* handle single page
*
* @param {object} request
* @param {object} response
*
*/
fastify.get('/*', async function(request, response) {
return response.view('../views/templates/page/' + response.locals.page.data.template)
})
}