+++ /dev/null
-#!/usr/bin/env node
-
-'use strict';
-
-const Fs = require('fs');
-const Path = require('path');
-
-const Hapi = require('@hapi/hapi');
-
-const InsultGenerator = require('../lib/InsultGenerator');
-
-const replaceRe = /{{insult}}/
-let template;
-
-
-const server = Hapi.Server({
- host: 'localhost',
- port: 9200
-});
-
-server.route({
- method: 'GET',
- path:'/',
- async handler(request, reply) {
- return template.replace(replaceRe, await InsultGenerator.generate());
- }
-});
-
-server.route({
- config: {
- cors: {
- origin: ['*'],
- additionalHeaders: ['cache-control', 'x-requested-with']
- }
- },
- method: 'GET',
- path:'/raw',
- handler: function (request, reply) {
-
- return InsultGenerator.generate();
- }
-});
-
-// Preload stuff, then run
-console.debug('Loading template...');
-Fs.readFile(Path.resolve(__dirname, '../ext/index.html'), {encoding: 'utf8'}, function (err, contents) {
-
- if (err) {
- console.error(err);
- process.exit(1)
- }
-
- template = contents;
- console.log('Setting up insults...')
- InsultGenerator.generate()
- .then(function (insult) {
-
- server.start(function() {
-
- console.debug('Server running at:', server.info.uri);
- });
- })
- .catch(function (err) {
-
- console.error(err);
- console.error('Error running insults... bad augur');
- process.exit(1);
- });
-});