|
@@ -36,7 +36,14 @@ if (cluster.isMaster) {
|
|
console.log('worker ' + worker.pid + ' died');
|
|
console.log('worker ' + worker.pid + ' died');
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- var server = module.exports = Hapi.createServer(null, 8080);
|
|
|
|
|
|
+ var server = module.exports = Hapi.createServer(null, 8080, {
|
|
|
|
+ views: {
|
|
|
|
+ engines: {
|
|
|
|
+ handlebars: 'handlebars'
|
|
|
|
+ },
|
|
|
|
+ path: __dirname + '/views'
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
server.route({
|
|
server.route({
|
|
method: 'GET',
|
|
method: 'GET',
|
|
@@ -90,5 +97,27 @@ if (cluster.isMaster) {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ server.route({
|
|
|
|
+ method: 'GET',
|
|
|
|
+ path: '/fortune',
|
|
|
|
+ handler: function(req){
|
|
|
|
+ if (windows) return req.reply(Hapi.error.internal('Not supported on windows'));
|
|
|
|
+
|
|
|
|
+ Fortune.all(function(err, fortunes){
|
|
|
|
+ fortunes.push({
|
|
|
|
+ id: 0,
|
|
|
|
+ message: 'Additional fortune added at request time.'
|
|
|
|
+ });
|
|
|
|
+ fortunes.sort(function(a, b){
|
|
|
|
+ return (a.message < b.message) ? -1 : 1;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ req.reply.view('fortunes.handlebars', {
|
|
|
|
+ fortunes: fortunes
|
|
|
|
+ }).header('Server', 'hapi');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
server.start();
|
|
server.start();
|
|
}
|
|
}
|