Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    devin ivy
    @devinivy
    this also will only work if hapi's payload parsing hasn't been disabled.
    Jonas Scheffner
    @jscheffner
    Hey, I'm trying to strip certain fields from my response. That doesn't seem to have any effect. Is it possible I misunderstand the strip method?
      server.route({
        method: 'GET',
        path: '/foo/{id}',
        handler: (req, reply) => {
          server.methods.fooHandler(req.params.id)
        },
        config: {
          response: {
            status: {
              200: joi.object(
                _id: joi.string(),
                name: joi.string(),
                updatedAt: joi.strip(),
                createdAt: joi.strip(),
                __v: joi.strip()
              )
            },
          }
        }
      })
    Jonas Scheffner
    @jscheffner
    I'm using Joi v10.5.2
    Jonas Scheffner
    @jscheffner
    Apparently I need to set the modify option to true
    Lioxor64
    @lioxor64

    Hello, my name is Liora and I am currently hunting open source projects for company NeuraLegion (www.neuralegion.com)
    We just launched a free annual subscription for open source projects for our AIAST tool NexPloit.

    If you are interested, please, reach us on opensource@neuralegion.com!

    Thank you for your time and consideration! If you have any questions, please do not hesitate to contact us!

    Best,

    Ben Chiciudean
    @benydc
    with Joi, what can I use to filter props from objects? in Ruby on Rails, there is sequelize. I was thinking about using json-mask but maybe Joi has something similar already integrated?
    Tõnis Ostrat
    @tonisostrat
    @benydc, "filter" how? do you mean you want to remove them?
    @benydc, if so then this might help you: https://github.com/hapijs/joi/blob/master/API.md#anystrip
    Ben Chiciudean
    @benydc
    yes, but want to specify the opposite of strip, to show only those fields
    Tõnis Ostrat
    @tonisostrat
    @benydc, in that case write up a schema with the fields you want to allow and then play around with the stripUnknown flag: https://github.com/hapijs/joi/blob/master/API.md#anyvalidatevalue-options
    Marwan Rabbâa
    @waghanza
    hello, does hapi support route contraint ?
    I mean somethin like /user/:id(\\d+)
    Yoann MALLEMANCHE
    @YoannMa
    why not validating it with Joi ?
    the example you gave is validating that id is an integer right ?
    Marwan Rabbâa
    @waghanza
    yeah
    Tõnis Ostrat
    @tonisostrat
    @waghanza, this is what @YoannMa is talking about: https://hapijs.com/tutorials/validation#pathparams
    Marwan Rabbâa
    @waghanza
    I'm trying to add this in the-benchmarker/web-frameworks#1207 (and I never used joi)
    Yoann MALLEMANCHE
    @YoannMa
    Hapi does not come with validation by itself, it use the joi package (made by the hapi org)
    you need to require it and your route config should be something like :
    server.route({
      method: 'GET',
      path: '/user/{id}',
      options : {
        validate : {
          params : {
            id : Joi.number().integer()
          }
        }
      },
      handler: function (req, handler) {
        return req.params.id
      }
    })
    Marwan Rabbâa
    @waghanza
    yep, it seems to work
    thx @tonisostrat @YoannMa
    Yoann MALLEMANCHE
    @YoannMa
    you're welcome
    Tõnis Ostrat
    @tonisostrat

    has anyone run into a problem where Hapi intermittently throws CORS access errors?

    we have an old backend server (Hapi 14.x) running on AWS and a frontend Angular service with a different URL. when the frontend queries the server sometimes it works just fine but then at other times it randomly errors out with CORS problems and i haven't been able to determine a pattern.

    the server side has the following code on initialization

    cors: {
      credentials: true
    }

    reading the docs it seems like without explicitly setting origin it defaults to ['*']

    Jan Opravil
    @opravil-jan
    Hello
    Jan Opravil
    @opravil-jan
    Is it possible when I throw a @hapi/boom exception (Boom.badRequest([message], [data])) and fill in parameter data to find this data in @hapi/good when processing event.response?
    Harsh Chaurasiya
    @harsh6768
    I am working on hapi 14.0 version with es5 and facing problem to store the logs in the mongodb database . Can anyone give example about how to save the logs in mongodb database using good logger.
             var Hapi=require('hapi');
             var routes=require('./Routes/routes');
             var admin=require('./Model/admin');
    
            admin.createAdmin();
    
    
           var port=process.env.port||3000;
           var server = new Hapi.Server()
    
          server.connection({
              port:port,
              host:'localhost',
             routes: {
                cors: true
           }
         })
    
    
        routes.forEach((route, index)=>{
             server.route(route)
        })   
    
    
         server.register(
       [
    
      {
            register:require('good'),
            options:{ 
                ops:{
                    interval:10000
                    },
                reporters:{
                        console:[
                            {
                            module:'good-squeeze',
                            name:'Squeeze',
                            args:[{log:'*',response:'*',request:'*'}]
                    },
                    {
                        module:'good-console'
                    },
                    'stdout'
                ]
            }
    
              }
    
            },
          ],
    function(err){
        if(err) {console.log('error',"failed to install plugins")
        throw err;
     }
     server.log("info","plugins registered")
    
     }
      );
    
    
         server.start( function(err){
      if(err) throw err;
      console.log('server running at '+server.info.uri );
    }
    Harsh Chaurasiya
    @harsh6768
    where do i have to add mongodb connection?
    Brandon Caruana
    @caruana
    hi all, noob question.
    I'm messing around (first time) with hapi and trying to use it with TypeScript. When I import * as Hapi from '@hapi/hapi' into my server.ts file I get the following error: Could not find a declaration file for module '@hapi/hapi'. '/Users/xx/project/node_modules/@hapi/hapi/lib/index.js' implicitly has an 'any' type.
    Google is not helping much so I thought I turn to Gitter
    Tõnis Ostrat
    @tonisostrat
    import * as Hapi from 'hapi';
    Brandon Caruana
    @caruana
    @tonisostrat I tried that "Error: Cannot find module 'hapi'
    my package.json dependencies ref is: "@hapi/hapi": "^18.3.2"
    Tõnis Ostrat
    @tonisostrat
    what about @types/hapi?
    Brandon Caruana
    @caruana
    yes, I have "@types/hapi": "^18.0.2",
    I pruned @hapi/hapi out and changed to hapi: ^18.0.2 (this jus worked)
    Tõnis Ostrat
    @tonisostrat
    ah, ok. i guess they've changed their project structure and the typings don't reflect that
    Brandon Caruana
    @caruana
    But i'm unclear on why @hapi/hapi doesn't (maybe the @types is not up to date)
    @tonisostrat ok, i'm guessing the same, thanks for the direction
    Brandon Caruana
    @caruana
    for anyone looking @hapi/hapi ^18.3.2 requires @types/hapi__hapi ^18.0.2
    Ben Chiciudean
    @benydc
    is it possible to provide default headers when using inject?
    Sitraka Ratsimba
    @sitraka-hq

    Hi! I'm not sure if it is a bug

    I'm using "@hapi/hapi": "^18.3.2", "@hapi/joi": "^16.0.1",

    My routes looks like:

    'use strict';
    
    const Joi = require('@hapi/joi');
    
    module.exports = [
        {
            method: 'GET',
            path: '/users/new',
            handler: (request, h) => {
    
                return h.view('users/new');
            }
        },
        {
            method: 'POST',
            path: '/users',
            handler: (request, h) => {
    
                return h.view('users/new');
            },
            options: {
                validate: {
                    payload: Joi.object().keys({
                        username: Joi.string()
                    })
                }
            }
        }
    ];

    I get the following error when I start the server:

     Error: Invalid schema content: ($_root.alternatives)
        at new module.exports (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hoek/lib/error.js:21:15)
        at Object.module.exports [as assert] (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hoek/lib/assert.js:20:11)
        at Object.exports.schema (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/cast.js:50:10)
        at internals.Object.keys (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/types/object/index.js:363:35)
        at Object.exports.schema (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/cast.js:31:29)
        at internals.Object.keys (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/types/object/index.js:363:35)
        at Object.exports.schema (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/cast.js:31:29)
        at module.exports.internals.Any.root.compile (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/node_modules/@hapi/joi/lib/index.js:157:25)
        at Object.exports.compile (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/lib/validation.js:21:49)
        at forEach (/home/sitraka/Projects/camoicenter/node_modules/@hapi/hapi/lib/route.js:196:43) path: '$_root.alternatives' }
    Sitraka Ratsimba
    @sitraka-hq
    @sitraka-hq hapijs/joi#2107
    Yoann MALLEMANCHE
    @YoannMa
    Joi already support trimming string and stripNullorEmpty IIRC
    Kan Yilmaz
    @thellimist
    Hi, I'm the founder of Kodem.io - Node.js deployments with no fancy configuration or modification. I'm mostly looking into hapijs out of personal interest. Thanks
    A
    @ybitso

    im having hard time finding good documentation on how to setup ssl
    this is what I have

        const server = hapi.server({
            port: port,
            host: configs.APIServer[env].Hostname,
            routes: {
                cors: {
                    origin: [configs.APIServer[env].Protocol +
                        "://" +
                        configs.WebServer[env].Hostname +
                        ":" +
                        configs.WebServer[env].Port, configs.WebServer[env].Protocol +
                        "://" +
                        configs.WebServer[env].IP +
                        ":" +
                    configs.WebServer[env].Port
                    ]
                }
            }
            // ,debug: {
            //     request: env === "production" ? ["error"] : ["error", "debug"]
            // }
        })

    do i just need to add on the bottom:

    , {
            tls: ssloptions
        }

    where ssloptions is the certs

    Will Hoover
    @ugate
    Does anyone know how to get details for @hapi/lab error: "The following leaks were detected:globalThis"? There doesn't seem to be any other output that indicates where the leak is occurring?
    Yoann MALLEMANCHE
    @YoannMa
    It can't find the leak for you sadly, most of the time it's from a library you are using
    Will Hoover
    @ugate
    That is disappointing :( I'm not sure how useful the option to detect leaks is if there isn't a straight forward path to resolve it
    Yoann MALLEMANCHE
    @YoannMa
    If you want, you can ignore this leak