Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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
    -I, --ignore - ignore a list of globals for the leak detection (comma separated), this is an alias of globals property in .labrc file. To ignore symbols, pass the symbol's string representation (e.g. Symbol(special)).
    Will Hoover
    @ugate
    That may be what I'll do if I can't find the cause of the leak. Thanks for the feedback @YoannMa !
    Yoann MALLEMANCHE
    @YoannMa
    It's not like you got much choice anyway, if you use Sentry for example, the library set a global __SENTRY__ so you need to ignore it....
    Will Hoover
    @ugate
    Good point!
    Will Hoover
    @ugate
    @YoannMa it looks like @hapi/lab has some issues with Node v12. I ran the same tests under Node v11 and no global leaks were detected, but when I run the same tests in Node v12 I get "The following leaks were detected:globalThis"
    Ben Chiciudean
    @benydc
    is there a API versioning for 18?
    so I can version my routes
    Yoann MALLEMANCHE
    @YoannMa
    There are plugin for it, but Hapi does not support it out of the box I believe
    Ben Chiciudean
    @benydc
    ahh, was looking for an out of the box support, I will check the plugin
    thanks
    Yoann MALLEMANCHE
    @YoannMa
    IMO, Hapi won't ever support api versioning out of the box
    CragVFX
    @CragVFX
    Does anyone know where I can find the hapi docs for v15? It appears like the site only goes back to 16.8 and I need to make a change to a v15 legacy route
    Tõnis Ostrat
    @tonisostrat
    you can choose a different tag depending on the specific version
    CragVFX
    @CragVFX
    @tonisostrat thanks thats what I was looking for 😀