]>
git.r.bdr.sh - rbdr/generador-de-insultos/blob - bin/server.js
13ae3813c1f6102675fd1e7818d175279b1b4c99
5 const Fs
= require('fs');
6 const Path
= require('path');
8 const Hapi
= require('@hapi/hapi');
10 const InsultGenerator
= require('../lib/InsultGenerator');
12 const replaceRe
= /{{insult}}/
16 const server
= Hapi
.Server({
24 async
handler(request
, reply
) {
25 return template
.replace(replaceRe
, await InsultGenerator
.generate());
33 additionalHeaders: ['cache-control', 'x-requested-with']
38 handler: function (request
, reply
) {
40 return InsultGenerator
.generate();
44 // Preload stuff, then run
45 console
.debug('Loading template...');
46 Fs
.readFile(Path
.resolve(__dirname
, '../ext/index.html'), {encoding: 'utf8'}, function (err
, contents
) {
54 console
.log('Setting up insults...')
55 InsultGenerator
.generate()
56 .then(function (insult
) {
58 server
.start(function() {
60 console
.debug('Server running at:', server
.info
.uri
);
63 .catch(function (err
) {
66 console
.error('Error running insults... bad augur');