Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Hello, guys I have a question about server methods
    let refreshData = function () {
          .search(deepCopy(AllProjectsQuery.query), null, "USE_CACHE")
          .then((data) => {
            logger.log('info', 'refresh all projects data succeed')
          .catch((err) => {
            logger.log('error', 'refresh all projects data error: %s', JSON.stringify(err))
    it says server.methods.search is not a function
    Currently I am migrating from v16 to v18, all seems to be working except this part. Maybe someone could give me a hint what is wrong?
    Peeter Tomberg
    Hey guys!
    Any idea on how I can enable streaming HTTP respones in Hapi?
    I tried hapijs/hapi#3599 but no success
    I've also tried removing compression (in server flags pass compression false) and then streaming but it all still gets sent in a single chunk
    Can any one Please help me to set HTTP response headers in Hapi ?
    For file downloads(CSV/TEXT)
    Hi, I'd need to implement catchall OPTIONS -method handling for a HAPI v19 based development server. What would be the simplest and least disruptive way to implement this? I was thinking of implementing a HTTP 404 handler that would check if it was an OPTIONS request and basically just turn the response into HTTP 200. I'm new to HAPI, so advice and/or pointers would be welcome. Also, I'd prefer to avoid adding new modules if possible. Any thoughts?
    Ok - I was able to implement a plugin for this, but would appreciate any pointers if there's a better / simpler way to do this.
    Anyone able to help me on how to get HAPI to generate CORS headers? access-control-allow-origin et al. are working ok, but how do I configure Access-Control-Allow-Methods? I'm currently generating *-methods header in my plugin, but just I'd prefer to use HAPI CORS config for this if possible.
    Fernando Ontiveros
    hi, I used hapi/nes for a web socket projects some years ago, but now I'm back, and can't make it work with latest version of @hapi and @hapi/nes and the browser as a client.
    can any of you point me to the right direction to make it work a simple web browser connect to @hapi/nes
    Fernando Ontiveros
    nevermind, I figure it out
    Hi, is the hapi hour slack no longer active? It seems the link on the website is broken
    Gerson Gallo
    thanks @ggallovalle! I was looking actually for a link to join the slack - for that direct link you need to already be on the slack for it to work, and the joining link on the website is expired
    Nav Saini
    Hi all! How do I introduce same-site: None to my hapi 15.x app?
    (SameSite: None) cookie
    Hi Friends, In hapi 19 does anyone knows how to pass parameter "config" in the route
    We upgraded from hapi-15 to hapi-19 recently . As part of upgrade, hapi-swagger got updated from 7.8.1 to 13.0.2, now we are seeing hapi-swagger-UI is completely removed with new version. Can anyone suggest on how to go with this.
    "<script src='{{hapiSwagger.swaggerUIPath}}lib/jquery-1.8.0.min.js' type='text/javascript'></script>" This is giving 404 in hapi-swagger 13.x which was working perfectly fine in hapi-swagger 7.x
    Daniel Ji
    for cached server methods (aka catbox caching) has anyone tried to use the pendingGenerateTimeout property? No matter what value I set or not defining it, I can't seem to get concurrent access to a cache item working. It always queues it up and the same object is returned. Here's the sample code. I try to access /route1 and then wait a few seconds then access /route2, but they both return the same exact item. I would expect that since there is no cached item initially, that the calls to /route1 and /route2 should return different objects?
      function sleep(ms) {
        return new Promise((resolve) => {
          setTimeout(resolve, ms);
      const querySchemaMetadata = async () => {
        console.log(`regenerating cache ${(new Date()).toLocaleTimeString()}`);
        await sleep(9000);
        return Promise.resolve([{id: `${(new Date()).getMilliseconds()}`}]);
      server.method('querySchemaMetadata', querySchemaMetadata, {
        cache: {
          expiresIn: 60 * 60 * 1000,  // 1hr
           * provides a 15 second timeout querySchemaMetadata to return. Otherwise, returns a timeout error
          generateTimeout: false,
          //generateTimeout: 15 * 1000,
           * returns a wrapped object of the value that includes additional stats metadata
          getDecoratedValue: true,
           * allow multiple simultaneous access requests to this cache item to be queued for up to a duration of
           * 10 seconds before a separate access request is allowed.
          pendingGenerateTimeout: 2000,
        path: '/route1',
        method: 'GET',
        handler: async function (request, h) {
          await server.methods.querySchemaMetadata()
        path: '/route2',
        method: 'GET',
        handler: async function (request, h) {
          await server.methods.querySchemaMetadata();
    Ario K
    I'm trying to pass a JSON string in a get request
    when recieve, do a JSON.parse
    However, I cannot access the properties inside after JSON.parse
    via a Joi.string().optional() validation
    is there anything else needed to make a GET from the browser into hapi besides cors: true ?
    what i'm doing is:
    const server = Hapi.server({
      port: 9000,
      host: 'localhost',
      routes: {
        cors: true
      method: 'GET',
      path: '/',
      handler: (request, h) => {
        return 'Hello World!';
    and I can see the response body with curl or httpie, but from browser (tested with svelte and react apps) just got the following:
    Response {type: "cors", url: "http://localhost:9000/", redirected: false, status: 200, ok: true, …}
    body: (...)
    bodyUsed: false
    headers: Headers {}
    ok: true
    redirected: false
    status: 200
    statusText: "OK"
    type: "cors"
    url: "http://localhost:9000/"
    __proto__: Response
    without any response body... anyway
    Matthew Adams
    How do I match multiple parameters in a route, like /providers/{providerId}/fulfillers/{fulfillerId}/customers/{customerId}? https://hapi.dev/api/?v=20.0.3#path-parameters says hapi can only match one. Do I really have to use /providers/{things*} then do something like things.split('/')? Seems like a burden.
    devin ivy
    hello, member of the hapi technical steering committee here :wave: just wanted to share with those here that there is an official hapi slack. please join us, it's pretty lively over there :) https://join.slack.com/t/hapihour/shared_invite/zt-g5ortpsk-ErlnRA2rUcPIWES21oXBOg
    Megha Modi
    Screen Shot 2021-02-03 at 1.17.10 PM.png
    Hi, I am unable to get the results on HTML page from the SQL query I am using. I am not sure what I am doing wrong in this piece of code.
    Anyone knows how to log responseBody in hapi-pino. Google is telling to use serializers but i am not able to find right example on how to use serializer and log responseBody
    Is it possible to set more than one cookie in hapi-auth-cookie using
    request.cookieAuth.set() ??
    Roy Keene
    cookieAuth.set() sets the data within the cookie, usually to some kind of object. The cookie is encrypted and sent to the client.
    Someone can help me ? I have a payload stream, but i cant take the data of this payload
    Someone know how can i do this ?
    Cem Basaranoglu
    pals, I have an awkward error. I'm working on a legacy project and I got this error most of the time. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
    TypeError: msg.socket.cork is not a function what do u think? node version: 14.16 hapi version: 17.8.1
    Ario K
    anyone have any idea what Joi validation I can use to accept any type of json string object?
    I upgrade Joi and now Joi.object().optional() doesn't work
    Is there any way to rewrite the request headers in the lifecycle hook pre or ext ?
    application/xml fails if parse is true (default) for route