Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    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?
    Ronald J Kimball
    @tamias
    Is it possible to specify the collection name for a MANY_MANY linking table? I've created a linking model named questionCategoryLink.model.js, which results in a collection named questionCategoryLink. I want the collection to be named questionCategoryLinks, to match the pluralization of all my other collection names.
    David Clarkson
    @djclarkson
    This project is great. Thank you!
    Would be really cool for a bit more examples for auth as mentioned earlier. Would love a basic hapi-rest hapi-auth-jwt2 example with a few routes (appy is great, but theres a lot of extra stuff going on in there which makes it a bit of a leap for something my level).
    Bonus would be inclusion of how to protect route like http://example.com/api/{userid}/profile
    Just not quite clear to me with the scope info in the docs.