2019-09-06 01:20:24 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
require('make-promises-safe'); // installs an 'unhandledRejection' handler
|
|
|
|
|
|
|
|
const path = require('path');
|
2019-09-07 02:23:55 +02:00
|
|
|
let siteConfig;
|
|
|
|
try {
|
|
|
|
siteConfig = require('./config.json');
|
|
|
|
} catch (ex) {
|
|
|
|
console.error('Please copy `config.example.json` to `config.json` and fill it with your server\'s data.');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
2019-09-06 01:20:24 +02:00
|
|
|
const fastify = require('fastify')({
|
2019-09-07 02:12:56 +02:00
|
|
|
logger: process.env.NODE_ENV !== 'production',
|
2019-09-06 01:20:24 +02:00
|
|
|
});
|
|
|
|
fastify.register(require('fastify-helmet'));
|
|
|
|
fastify.register(require('fastify-compress'));
|
|
|
|
fastify.register(require('fastify-formbody'));
|
|
|
|
fastify.register(require('fastify-static'), {
|
|
|
|
root: path.join(__dirname, 'public'),
|
|
|
|
});
|
|
|
|
fastify.register(require('point-of-view'), {
|
|
|
|
engine: {
|
|
|
|
handlebars: require('handlebars'),
|
|
|
|
},
|
|
|
|
templates: 'views',
|
|
|
|
options: {
|
|
|
|
useHtmlMinifier: require('html-minifier'),
|
|
|
|
htmlMinifierOptions: {
|
|
|
|
removeComments: true,
|
|
|
|
removeCommentsFromCDATA: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
removeEmptyAttributes: true
|
|
|
|
},
|
|
|
|
partials: {
|
2019-09-07 00:24:42 +02:00
|
|
|
layout: 'layout.hbs',
|
2019-09-06 01:20:24 +02:00
|
|
|
header: 'partials/header.hbs',
|
|
|
|
footer: 'partials/footer.hbs',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-09-07 02:23:55 +02:00
|
|
|
fastify.decorate('siteConfig', siteConfig);
|
|
|
|
|
2019-09-06 01:20:24 +02:00
|
|
|
// Routes
|
|
|
|
fastify.register(require('./routes/resources'));
|
|
|
|
fastify.register(require('./routes/home'));
|
2019-09-07 01:20:27 +02:00
|
|
|
fastify.register(require('./routes/search'));
|
2019-09-06 01:20:24 +02:00
|
|
|
|
|
|
|
// Start the server
|
2019-09-07 02:23:55 +02:00
|
|
|
fastify.listen(fastify.siteConfig.port, function (err, address) {
|
2019-09-06 01:20:24 +02:00
|
|
|
if (err) {
|
|
|
|
fastify.log.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
fastify.log.info(`server listening on ${address}`);
|
|
|
|
});
|