]>
git.r.bdr.sh - rbdr/generador-de-insultos/blob - bin/server.js
00c23bbb8dc9325df89fdfd3c601bc9e2cd54257
5 var fs
= require('fs');
6 var path
= require('path');
8 var Hapi
= require('hapi');
10 var server
= new Hapi
.Server();
11 var InsultGenerator
= require('../lib/InsultGenerator');
13 var insults
= new InsultGenerator({
14 file : path
.resolve(__dirname
, '../ext/words.tab')
16 var replaceRe
= /{{insult}}/
28 handler: function (request
, reply
) {
29 insults
.generate().then(function (insult
) {
30 reply(template
.replace(replaceRe
, insult
));
39 additionalHeaders: ['cache-control', 'x-requested-with']
44 handler: function (request
, reply
) {
45 insults
.generate().then(function (insult
) {
51 // Preload stuff, then run
52 console
.log("Loading template...");
53 fs
.readFile(path
.resolve(__dirname
, '../ext/index.html'), {encoding: 'utf8'}, function (err
, contents
) {
61 console
.log("Setting up insults...")
62 insults
.generate().then(function (insult
) {
63 server
.start(function() {
64 console
.log('Server running at:', server
.info
.uri
);
66 }).catch(function (err
) {
68 console
.log("Error running insults... bad augur");