Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Justin Headley
    @JKHeadley
    @ilyas-shah would you mind posting your middleware here?
    Ilyas Shah
    @ilyas-shah
    @JKHeadley
    list: {
    pre: function (query, request, Log) {
    query.$embed = query.$embed || [];
    if (query.$embed.indexOf('activity') < 0) {
    query.$embed.push('activity')
    }
    return query;
    },
    post: function(request, result, Log) {
    const Invoice = mongoose.model('invoice');
                    let promises = [];
    
                    result.forEach(function(invoice) {
                        promises.push(Invoice.setUserActivityStatusForInvoice(invoice, Log));
                    });
    
                    return Q.all(promises)
                        .then(function() {
                            return result
                        })
                }
            }
    Justin Headley
    @JKHeadley

    @ilyas-shah that looks like the list middleware, while the error is occurring in add middleware. I don't see any immediate problems here. Maybe it is occurring in the setUserActivityStatusForInvoice function?

    Also, the error seems to indicate that this happens while creating an invoice. I would have to see more code to know exactly where the issue is. If it's possible for you to provide me a link to your repo I will try to take a look.

    Derk Weijers
    @derkweijers
    Hi Everyone! I hope someone is able to help me. I'm trying to create a simple API that's open for anyone, except the CUD methods. I know I can accomplish this with routeOptions, but that requires authStrategy to be setup. Basic authentication is fine for now, but I'm not sure where to start to implement this strategy
    Derk Weijers
    @derkweijers
    Do I need to pass the name that I define in server.auth.strategy to authStrategy on the config object?
    Derk Weijers
    @derkweijers
    Figured it out, passing the name is correct. I had to to set readAuth on the right endpoints as well :)
    Shiva
    @shiva
    Has anyone used an auth library like passport or service like
    auth0 wth rest hapi? If yes, any examples?
    David Landry
    @davad
    @shiva I just implemented jwt auth with RestHapi
    Here’s a summary of what I had to do:
    • Create login/logout API endpoints
    • Create auth plugin (plugins/auth.plugin.js) - Defines and initializes auth strategies
    • Register hopi-auth-jwt2 and my custom auth.plugin.js with Hapi
    I pulled from appy-backend for inspiration
    karabaralex
    @karabaralex
    Hi, guys. Question: when I'm making API request to hapi-generated endpoint e.g. /api/user is there any way to add query like "age: { $gt: 17, $lt: 66 }" Does it work out of the box or I need to add custom endpoint args?
    David Landry
    @davad
    @karabaralex I think you’d need a custom endpoint. You can search by exact and partial values. E.g. you should be able to select users with an age of 19, but I don’t think you can use arbitrary Mongo operators.
    But you might as well try first :)
    karabaralex
    @karabaralex
    thanks. I tried. Does not seem to be working
    David Landry
    @davad
    @JKHeadley Is there a way to disable parts of the generated Joi validation?
    I want to pass something like this to Create/Update routes:
    {  embeddedDocument: { <some structure> } }
    My model schema looks like this:
    {  embeddedDocument: {
        type: ObjectId,
        ref: "embeddedDocumentSchema"
    } }
    And I've created a mongoose pre-validate middleware function that extracts the object from embeddedDocument, saves it to using embeddedDocumentSchema, and replaces the original embeddedDocument object with an ObjectID.
    But the RestHapi autogenerated Joi validation requires embeddedDocument to be passed as a string.
    David Landry
    @davad
    @JKHeadley Could you take a look at my issue and PR? JKHeadley/rest-hapi#163
    David Landry
    @davad
    Has anyone tried using the Mongoose v5 Map type with RestHapi?
    David Landry
    @davad
    FYI, I ran into a bug when using a Map field, JKHeadley/rest-hapi#166
    I have a tentative fix in a PR.
    Shiva
    @shiva
    @davad Thanks! That sounds like a bunch of work to attempt one of these days.
    Another n00b question: I am attempting to host the rest-hapi app with a baseurl prefix -- foo.com/api as an example
    Here is my hapi server config:
    Shiva
    @shiva
    await server.register({
      plugin: RestHapi,
      options: {
        mongoose: mongoose,
        config: config,
        routes: {
          prefix: '/api'
        }
      },  
    })  
    However, the swagger api generated doesn't seem to point to the correct urls. What am I missing?
    Justin Headley
    @JKHeadley
    @shiva do you mean to set the swagger/docs path or the api path?
    Justin Headley
    @JKHeadley
    FYI, currently rest-hapi does not accept config options for either. The correct hapi-swagger options to set would be either basePath or documentationPath (as seen here: https://github.com/glennjones/hapi-swagger/blob/master/optionsreference.md)
    These options would need to be passed in to the swagger config here: https://github.com/JKHeadley/rest-hapi/blob/b069959a8813ecc01124fe38e8b03817ff66b6b9/rest-hapi.js#L220
    I would like to add a general swagger config object so that all hapi-swagger options could be configured via rest-hapi.
    Shiva
    @shiva
    @JKHeadley You hit the nail on the head. Will work on it, and raise a pull request.
    Shiva
    @shiva
    Actually both. If one were to host the rest-hapi server at a different base-path, it would make sense that all url use that as the base. How would I ensure both of them are prefixed with the base path.
    Shiva
    @shiva
    @JKHeadley For all of rest-hapi generated endpoints to have a baseurl, will I have to modify all such points such as https://github.com/JKHeadley/rest-hapi/blob/b069959a8813ecc01124fe38e8b03817ff66b6b9/utilities/rest-helper-factory.js#L213 and include some "basePath" specified in config?
    am I reading this right? or is there a simpler way?
    Shiva
    @shiva
    @JKHeadley Just raised a pull request (JKHeadley/rest-hapi#172) Let me know if it is in line with your thoughts
    Shiva
    @shiva
    @JKHeadley Did you need me to squash commits etc for the pull request? Anything I can do to expedite the change?
    Justin Headley
    @JKHeadley
    @shiva just commented on the PR, sorry for the delay.
    Shiva
    @shiva
    @JKHeadley Thanks for the support in merging the PR! Thanks for enabling hosting of the generated API ep at a prefix.
    wowtech
    @wowtech_gitlab
    How can we use authentication ?
    Justin Headley
    @JKHeadley

    @wowtech_gitlab apologies for the lack of documentation on authentication, I'll have to fix that.

    Short answer: use a hapi auth plugin such as hapi-auth-jwt2and set the config.authStrategy option.

    You can see a working example in the appy project:
    https://github.com/JKHeadley/appy/blob/master/backend/server/plugins/auth.plugin.js
    https://github.com/JKHeadley/appy/blob/a009a81ea0b80c39ccd01813def7d3d1956f9168/backend/config/manifest.conf.js#L43
    https://github.com/JKHeadley/appy/blob/a009a81ea0b80c39ccd01813def7d3d1956f9168/backend/config/index.js#L215

    I will work on getting a better explanation in the docs and let you know once it's done.

    Naveen N
    @resistancet9
    hi
    i just created a file called auth.js in api folder. i added /public endpoint with auth set to null.
    when i access /public via postman. im getting 401 status
    what am i missing?
    Naveen N
    @resistancet9
    hapi-auth-jwt2 ive added this one
    Justin Headley
    @JKHeadley
    @resistancet9 it's hard to tell without more information. If you can direct me to your repo or post some code here I will try to take a look.
    Justin Headley
    @JKHeadley
    @wowtech_gitlab @resistancet9 please see the updated docs for information on how to set up authentication: https://resthapi.com/docs/authentication.html
    jlconrad3
    @jlconrad3
    Anyone know how to create an array inside a collection?