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.

66 lines
1.2 KiB

import fastify from 'fastify'
import dotenv from 'dotenv'
import path from 'path'
// getting .env
dotenv.config({ path: path.join(path.resolve(), '/../../.env') })
// create server
const server = fastify()
/**
* Add liquidjs
*
*
*/
import { Liquid } from 'liquidjs'
import view from '@fastify/view'
const engine = new Liquid({
root: path.join(path.resolve(), '/../frontend/views'),
extname: '.liquid',
})
server.register(view, {
engine: {
liquid: engine
}
})
/**
* adding preHandler
*
*/
import OptionStore from './stores/Option.js'
// getting options from directus add to all views
server.addHook('preHandler', async function (request, response) {
const optionStore = new OptionStore()
const options = await optionStore.find()
response.locals = {
options: options
}
})
// routing
import notfoundHttp from './http/notfound.js'
import postHttp from './http/post.js'
// page and static has always the last routes, if no route before match, it try get a page
import pageHttp from './http/page.js'
import staticHttp from './http/static.js'
server
.register(notfoundHttp)
.register(postHttp, {
'prefix': '/blog'
})
.register(pageHttp)
.register(staticHttp)
export default server