Move point-of-view setup to separate file
This commit is contained in:
parent
0bbfafd03f
commit
621ee61144
22
server.js
22
server.js
|
@ -21,27 +21,7 @@ fastify.register(require('fastify-formbody')); // Enable fastify to parse data
|
||||||
fastify.register(require('fastify-static'), { // Enable delivering static content efficiently
|
fastify.register(require('fastify-static'), { // Enable delivering static content efficiently
|
||||||
root: path.join(__dirname, 'public'), // all static content will be delivered from the public/ folder
|
root: path.join(__dirname, 'public'), // all static content will be delivered from the public/ folder
|
||||||
});
|
});
|
||||||
fastify.register(require('point-of-view'), { // Adds the `view()` function to fastify's `reply` objects
|
fastify.register(require('point-of-view'), require('./views/viewSetup')); // Adds the `view()` function to fastify's `reply` objects
|
||||||
engine: {
|
|
||||||
handlebars: require('handlebars'), // Use handlebar as the render engine for `reply.view()`
|
|
||||||
},
|
|
||||||
templates: 'views', // Search for all files referenced in `reply.view()` within the `views/` folder
|
|
||||||
options: {
|
|
||||||
useHtmlMinifier: require('html-minifier'), // Add a minifier to the rendered HTML output
|
|
||||||
htmlMinifierOptions: {
|
|
||||||
removeComments: true,
|
|
||||||
removeCommentsFromCDATA: true,
|
|
||||||
collapseWhitespace: true,
|
|
||||||
collapseBooleanAttributes: true,
|
|
||||||
removeEmptyAttributes: true
|
|
||||||
},
|
|
||||||
partials: { // Specifies the Handlebars Partials so `point-of-view` knows where they are within the `views` folder and what they're called when referenced in a `.hbs` file
|
|
||||||
layout: 'layout.hbs',
|
|
||||||
header: 'partials/header.hbs',
|
|
||||||
footer: 'partials/footer.hbs',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
fastify.register(require('fastify-cookie')); // Enable reading and setting http-level cookies for the sole purpose of storing login tokens
|
fastify.register(require('fastify-cookie')); // Enable reading and setting http-level cookies for the sole purpose of storing login tokens
|
||||||
fastify.register(require('fastify-jwt'), { // Enable creating, parsing, and verifying JSON Web Tokens from the global fastify object
|
fastify.register(require('fastify-jwt'), { // Enable creating, parsing, and verifying JSON Web Tokens from the global fastify object
|
||||||
secret: fastify.siteConfig.jwtSecretKey, // The secret key used to generate JWTs. Make it big and random!
|
secret: fastify.siteConfig.jwtSecretKey, // The secret key used to generate JWTs. Make it big and random!
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const partialFiles = fs.readdirSync(path.resolve(__dirname, 'partials')); // This is resolved from *this file's* dirname
|
||||||
|
const partials = {
|
||||||
|
layout: 'layout.hbs',
|
||||||
|
};
|
||||||
|
partialFiles.forEach(file => {
|
||||||
|
if (file.includes('.hbs')) {
|
||||||
|
const name = file.replace('.hbs', '');
|
||||||
|
partials[name] = `partials/${file}`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = { // Adds the `view()` function to fastify's `reply` objects
|
||||||
|
engine: {
|
||||||
|
handlebars: require('handlebars'), // Use handlebar as the render engine for `reply.view()`
|
||||||
|
},
|
||||||
|
templates: 'views', // Search for all files referenced in `reply.view()` within the `views/` folder
|
||||||
|
options: {
|
||||||
|
useHtmlMinifier: require('html-minifier'), // Add a minifier to the rendered HTML output
|
||||||
|
htmlMinifierOptions: {
|
||||||
|
removeComments: true,
|
||||||
|
removeCommentsFromCDATA: true,
|
||||||
|
collapseWhitespace: true,
|
||||||
|
collapseBooleanAttributes: true,
|
||||||
|
removeEmptyAttributes: true
|
||||||
|
},
|
||||||
|
partials, // Specifies the Handlebars Partials so `point-of-view` knows where they are within the `views` folder and what they're called when referenced in a `.hbs` file
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue