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 PageStore from './../stores/Post.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 store.findOneBySlug(request.params.slug)
directusResponseHandler.one(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('../frontend/views/templates/post/' + response.post.data..template, {
'page' : post
})
})
}