Express offers something similar to organize/simplify your routing:<p><pre><code> var express = require('express');
var appRoot = express();
var appFoobar = express();
appFoobar.get('/bar', function (req, res) { res.end('/foo/bar'); });
appRoot.use('/foo', appFoobar);
appRoot.listen(process.env.PORT);
$ curl localhost:3000/foo/bar
/foo/bar
$
</code></pre>
As for "monkey patching", overwriting methods is often a bad idea. It may be better to use a new method to call upon the old one:<p><pre><code> Hapi.Server.prototype.routeAPI = function (routes) {
if (!Array.isArray(routes)) routes = [ routes ];
routes = routes.map(function (route) {
route.path = '/api' + route.path;
return route;
});
return this.route(routes);
}
</code></pre>
Like nadadiv said, you could even have gone without recreating a Server() instance each time.
> server.route = new Hapi.Server().route;<p>Seems wasteful to create an instance only to get a property, when you can just use `Hapi.Server.prototype.route` instead