From 5c1538a82b2221cfbcf7577c6888a8c0f68fa520 Mon Sep 17 00:00:00 2001 From: Aaron Tribou Date: Mon, 14 Sep 2015 21:43:06 -0500 Subject: [PATCH] Migrate to Hapi 9.x --- package.json | 6 +++-- server.js | 72 +++++++++++++++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index b73fdaa..36af030 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,13 @@ "dependencies": { "dateformat": "^1.0.11", "flux": "^2.0.3", - "hapi": "^8.8.0", + "hapi": "^9.3.1", "hapi-react-views": "^3.0.1", + "inert": "^3.0.1", "object-assign": "^3.0.0", "react": "^0.13.3", - "superagent": "^1.2.0" + "superagent": "^1.2.0", + "vision": "^3.0.0" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", diff --git a/server.js b/server.js index 0a430aa..abcd702 100644 --- a/server.js +++ b/server.js @@ -14,37 +14,51 @@ server.connection({ port: 8000 }); -// Add the React-rendering view engine -server.views({ - engines: { - jsx: require('hapi-react-views') - }, - relativeTo: __dirname, - path: 'views' -}); +// Register the inert and vision Hapi plugins +// As of Hapi 9.x, these two plugins are no longer +// included in Hapi automatically +// https://github.com/hapijs/hapi/issues/2682 +server.register([{ + register: require('inert') +}, { + register: require('vision') +}], function(err) { -// Add a route to serve static assets (CSS, JS, IMG) -server.route({ - method: 'GET', - path: '/{param*}', - handler: { - directory: { - path: 'assets', - index: ['index.html'] - } - } -}); + if (err) return console.error(err); -// Add main app route -server.route({ - method: 'GET', - path: '/', - handler: { - view: 'Default' - } -}); + // Add the React-rendering view engine + server.views({ + engines: { + jsx: require('hapi-react-views') + }, + relativeTo: __dirname, + path: 'views' + }); + + // Add a route to serve static assets (CSS, JS, IMG) + server.route({ + method: 'GET', + path: '/{param*}', + handler: { + directory: { + path: 'assets', + index: ['index.html'] + } + } + }); + + // Add main app route + server.route({ + method: 'GET', + path: '/', + handler: { + view: 'Default' + } + }); + + server.start(function() { + console.log(dateFormat(new Date(), format) + ' - Server started at: ' + server.info.uri); + }); -server.start(function() { - console.log(dateFormat(new Date(), format) + ' - Server started at: ' + server.info.uri); });