import PostStore from './../stores/post.js' import directusResponseHandler from './../handlers/directusResponse.js' import path from 'path' /** * post * * @author Björn Hase * @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 postStore = new PostStore() // getting single page let post = await postStore.findOneBySlug(request.params.slug) directusResponseHandler.single(post, response) }) /** * handle single post * * @param {object} request * @param {object} response * */ fastify.get('/:slug([-a-zA-Z0-9]{0,255})', async function(request, response) { response.view('../views/templates/post/' + response.locals.page.data.template) }) }