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.

45 lines
1.1 KiB

import PostStore from './../stores/post.js'
import directusResponseHandler from './../handlers/directusResponse.js'
import path from 'path'
/**
* post
*
* @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 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)
})
}