[–] amasad 12y ago ↗ FYI - no need for underscore if you're only targeting node.js. You can use Array.isArray and routes.map instead of _.isArray and _.map
[–] nadaviv 12y ago ↗ > server.route = new Hapi.Server().route;Seems wasteful to create an instance only to get a property, when you can just use `Hapi.Server.prototype.route` instead [–] [deleted] 12y ago ↗ (comment deleted) [–] sek 12y ago ↗ True, is the de facto standard super call in js.Changed it
[–] joshguthrie 12y ago ↗ Express offers something similar to organize/simplify your routing: 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 $ 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: 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); } Like nadadiv said, you could even have gone without recreating a Server() instance each time. [–] sek 12y ago ↗ Yeah unfortunately hapi didn't, but this was one of the rare cases when it's not superior to express.I probably take it out once I am out of development so all the route methods stay untouched. [–] nadaviv 12y ago ↗ There's also an express library that I wrote some time ago that allows you to create subroutes without using subapps:https://github.com/shesek/express-subroute
[–] sek 12y ago ↗ Yeah unfortunately hapi didn't, but this was one of the rare cases when it's not superior to express.I probably take it out once I am out of development so all the route methods stay untouched.
[–] nadaviv 12y ago ↗ There's also an express library that I wrote some time ago that allows you to create subroutes without using subapps:https://github.com/shesek/express-subroute
8 comments
[ 5.0 ms ] story [ 41.4 ms ] threadSeems wasteful to create an instance only to get a property, when you can just use `Hapi.Server.prototype.route` instead
Changed it
I probably take it out once I am out of development so all the route methods stay untouched.
https://github.com/shesek/express-subroute