3

I the following code in my hapijs (nodejs) project

var t = require('joi');
var bdd = require('./../bdd');

module.exports = [
{
    method: 'GET',
    path: '/getAllParties',
    handler: function (request, reply) {
          //some code
    },
    config:{
        description: this.path + " route."
    }
}
];

But when a load my route i see :

: description = undefined route. ...

How do I set this value ?

user1740962
  • 111
  • 2
  • 16

2 Answers2

0

In your example this doesn't refer to the object you're trying to export. What you could do is use a function at this point called getConfig to return an object with that information:

module.exports = [{
    method: 'GET',
    path: '/getAllParties',
    handler: function (request, reply) {
        //some code
    },
    getConfig: function () {
        return {
            description: this.path + " route."
        }
    }
}]


obj[0].getConfig().description; // "/getAllParties route."

DEMO

Andy
  • 61,948
  • 13
  • 68
  • 95
  • i can change the structure ... this is for hapijs (with mrHorse), i try description : function(){ return this.path} but my application doesn' t start – user1740962 Apr 27 '15 at 09:45
  • I don't know what that means. – Andy Apr 27 '15 at 09:46
  • its a nodejs application not standard javascript ... and this object is for hapijs ( http://hapijs.com/ ) with your solution i have a error : " description is not a string " – user1740962 Apr 27 '15 at 10:08
-1

You missed the ];

var t = require('joi');
var bdd = require('./../bdd');

module.exports = [
{
    method: 'GET',
    path: '/getAllParties',
    handler: function (request, reply) {
          //some code
    },
    config:{
        description: this.path + " route."
    }
}
Fathan
  • 112
  • 1
  • 4