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