profile
viewpoint

arb/celebrate 988

A joi validation middleware for Express.

arb/big-time 2

Big time makes it possible to have a timeout that is longer than 24.8 days (2^31-1 milliseconds).

arb/as-god-intended 1

Enforce callback style asynchronous programming

arb/bracketing 1

Function to efficiently traverse large strings or arrays and run a predicate on adjacent values.

arb/async 0

Async utilities for node and the browser

arb/bassmaster 0

Batch request plugin for hapi

arb/bell 0

Third-party login plugin for hapi

arb/belly-button 0

Continuation Labs Linter

arb/boom 0

HTTP-friendly error objects

issue commentsideway/joi

defaults in ordered array are not filled

Would love to see this fixed ! 😄

everhardt

comment created time in an hour

issue commenthapijs/hapi

how do i handle errors with streams in hapi?

This solution will be somewhat specific to the stream you are handling, but it makes sense that it can work.

The method used should be quite safe, and could possibly be applied to all streams by hapi to give it a chance to error before starting the actual transmission. I don't know if this is something we would want to do?

Btw. the pause() should not be needed, as attaching a 'readable' handler is already supposed to do this.

fiws

comment created time in 2 hours

startedarb/celebrate

started time in 5 hours

issue commenthapijs/hapi

how do i handle errors with streams in hapi?

In case anyone has the same problem: I am now waiting for the stream to become readable before passing it to hapi. This makes catching "not found" errors and other setup related errors very easy. This is better than manually pre-checking imo, as it has less problems with race conditions. This effectively solved our problem:

const hapi = require('@hapi/hapi');
const fs = require('fs')

const server = hapi.server({ port: 1234 });

const streamReadable = stream => {
  stream.pause();
  return new Promise((resolve, reject) => {
    stream.once('error', reject);
    stream.once('readable', () => resolve(stream));
  });
};

server.route({
  method: 'GET',
  path: '/',
  async handler({ raw }, h) {
    const stream = fs.createReadStream('./notFound.txt');

    const readyStream = await streamReadable(stream);
    return h.response(readyStream);
  },
});

server.start()
  .then(() => console.log('Server running on %s', server.info.uri));

(not sure if this works for every stream source tho)

fiws

comment created time in 9 hours

issue commenthapijs/hapi

how do i handle errors with streams in hapi?

No. Once the response has started transmission there is no other way to signal an error than to forcefully close the connection.

fiws

comment created time in 10 hours

issue commenthapijs/hapi

how do i handle errors with streams in hapi?

thanks for the explanation. we will implement the validation before starting the stream.

Do you think there still is a workaround/hack to get hapi to always respond with a status code somehow tho?

The reason I am asking is because we are using Google Cloud Run and it seems that closing connections without sending anything is factored into some health metric. Our running containers seem to get replaced after repeatedly closing connections, which basically can be used as a DoS.

fiws

comment created time in 10 hours

issue commenthapijs/hapi

ETags adjusted for "content-encoding" are not correct

Afaik, a browser or caching proxy only needs strong ETags when it has a partial response and wants to expand on this using a Range request. For normal caching purposes weak ETags are fine.

kanongil

comment created time in 10 hours

issue commenthapijs/hapi

ETags adjusted for "content-encoding" are not correct

Yes, just always set a weak etag instead of the -gzip (when adding a compressor). I don't believe this will have any adverse effect.

The fact that I can provoke the issue using flushing is just a detail. The issue can in theory occur on any normal transmission, as there is no requirement for a compressor to produce the same output from the same input. Another way to provoke the issue, is to set a custom compressor and change the compression level (eg. in response to server CPU load).

kanongil

comment created time in 10 hours

issue commentsideway/joi-date

Documentation missing

Joi is not part of the hapi ecosystem anymore. You'll find the joi-date documentation here: https://joi.dev/module/joi-date/.

doktormerlin

comment created time in 11 hours

issue commentarb/celebrate

TypeScript Error: Type 'P' does not satisfy the constraint 'Params'. Type 'P' is not assignable to type 'ParamsArray'.

@arb I'm not sure if it would help since the application using celebrate still needs to have express and the express types package installed anyway. From what I read this has been a frequent issue with express and its types package.

nathan815

comment created time in 13 hours

issue commentsideway/joi

Issue after updating to latest Joi and Hapi versions.

Any feedback on this please?

ewein

comment created time in 17 hours

startedarb/celebrate

started time in 17 hours

issue closedhapijs/hapi

Please help me to make it work!

<!-- ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ You must complete this entire issue template to receive support. You MUST NOT remove, change, or replace the template with your own format. A missing or incomplete report will cause your issue to be closed without comment. Please respect the time and experience that went into this template. It is here for a reason. Thank you! ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ -->

I'm trying to make my single page app using angular to work, the last step is making the routing to work. The only hope I found was on this thread https://stackoverflow.com/questions/55577601/how-to-get-routing-to-work-in-hapijs-angular

Well the code provided cannot compile on the current version of your lib! Should I ask help to whom? Its very frustrating believe me...

My main issues right now is based on this couple of code cant compile because the thread its too old... its hard to believe nobody want to do that!


this.server.ext('onPreResponse', (request, h) => {
            const response = request.response;
        
            if (!response.isBoom) {
              return h.continue;
            }
        
            if (response.output.statusCode === 404) {
              return h.file('index.html');
            }
          });

[ERROR] 23:30:05 ⨯ Unable to compile TypeScript:
src/app.ts:71:27 - error TS2339: Property 'isBoom' does not exist on type 'Boom<any> | ResponseObject'.
  Property 'isBoom' does not exist on type 'ResponseObject'.

71             if (!response.isBoom) {
                             ~~~~~~
src/app.ts:75:26 - error TS2339: Property 'output' does not exist on type 'Boom<any> | ResponseObject'.
  Property 'output' does not exist on type 'ResponseObject'.

75             if (response.output.statusCode === 404) {
                            ~~~~~~
src/app.ts:76:24 - error TS2339: Property 'file' does not exist on type 'ResponseToolkit'.

76               return h.file('index.html');

Sorry I had really nobody to ask for clarifications anymore...

Support plan

<!-- We are here to help!

Community based support is, by its nature, limited to available community members able to help. Most community support issues are resolved within 2 weeks. Before submitting an issue, please review the various support options available at https://hapi.dev/support/. That page includes useful information about different ways to ask questions. -->

  • is this issue currently blocking your project? (yes/no):
  • is this issue affecting a production system? (yes/no):

Context

  • node version:
  • module version:
  • environment (e.g. node, browser, native):
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:

How can we help?

<!-- Describe your question in detail, including what you have already tried, or any configuration, schemas, code samples, or inputs needed. Make sure to wrap all code examples in backticks so that they display correctly. Before submitting an issue, make sure to click on the Preview tab above to verify everything is formatted correctly. -->

const some = 'properly formatted code example';

closed time in 19 hours

jbarros35

issue commenthapijs/hapi

Please help me to make it work!

I am going to close this out because it doesn't follow the issue template, and the issue you're running into seems to be related to typescript usage rather than hapi usage. A search for your typescript error turned this up, though, and perhaps it will be useful to you: https://stackoverflow.com/questions/54184444/how-to-fix-typescript-error-property-isboom-does-not-exist-on-type-boomany. You can also join the hapi hour slack, which has a #typescript channel for further community support: https://join.slack.com/t/hapihour/shared_invite/zt-g5ortpsk-ErlnRA2rUcPIWES21oXBOg

jbarros35

comment created time in 19 hours

issue commenthapijs/hapi

ETags adjusted for "content-encoding" are not correct

Would your recommendation be to always default to weak etags when serving compressed files rather than encoding-suffixed strong etags? Or perhaps only do this when the response stream has a custom setCompressor()? I wonder if there also might be an opportunity for h.entity() to support the same weak option provided by response.etag().

kanongil

comment created time in 19 hours

issue openedhapijs/hapi

Please help me to make it work!

<!-- ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ You must complete this entire issue template to receive support. You MUST NOT remove, change, or replace the template with your own format. A missing or incomplete report will cause your issue to be closed without comment. Please respect the time and experience that went into this template. It is here for a reason. Thank you! ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ -->

I'm trying to make my single page app using angular to work, the last step is making the routing to work. The only hope I found was on this thread https://stackoverflow.com/questions/55577601/how-to-get-routing-to-work-in-hapijs-angular

Well the code provided cannot compile on the current version of your lib! Should I ask help to whom? Its very frustrating believe me...

My main issues right now is based on this couple of code cant compile because the thread its too old... its hard to believe nobody want to do that!


this.server.ext('onPreResponse', (request, h) => {
            const response = request.response;
        
            if (!response.isBoom) {
              return h.continue;
            }
        
            if (response.output.statusCode === 404) {
              return h.file('index.html');
            }
          });

[ERROR] 23:30:05 ⨯ Unable to compile TypeScript:
src/app.ts:71:27 - error TS2339: Property 'isBoom' does not exist on type 'Boom<any> | ResponseObject'.
  Property 'isBoom' does not exist on type 'ResponseObject'.

71             if (!response.isBoom) {
                             ~~~~~~
src/app.ts:75:26 - error TS2339: Property 'output' does not exist on type 'Boom<any> | ResponseObject'.
  Property 'output' does not exist on type 'ResponseObject'.

75             if (response.output.statusCode === 404) {
                            ~~~~~~
src/app.ts:76:24 - error TS2339: Property 'file' does not exist on type 'ResponseToolkit'.

76               return h.file('index.html');

Sorry I had really nobody to ask for clarifications anymore...

Support plan

<!-- We are here to help!

Community based support is, by its nature, limited to available community members able to help. Most community support issues are resolved within 2 weeks. Before submitting an issue, please review the various support options available at https://hapi.dev/support/. That page includes useful information about different ways to ask questions. -->

  • is this issue currently blocking your project? (yes/no):
  • is this issue affecting a production system? (yes/no):

Context

  • node version:
  • module version:
  • environment (e.g. node, browser, native):
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:

How can we help?

<!-- Describe your question in detail, including what you have already tried, or any configuration, schemas, code samples, or inputs needed. Make sure to wrap all code examples in backticks so that they display correctly. Before submitting an issue, make sure to click on the Preview tab above to verify everything is formatted correctly. -->

const some = 'properly formatted code example';

created time in 20 hours

issue closedsideway/joi

Check two fields have a same specific value and allow another value

<!-- ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ You must complete this entire issue template to receive support. You MUST NOT remove, change, or replace the template with your own format. A missing or incomplete report will cause your issue to be closed without comment. Please respect the time and experience that went into this template. It is here for a reason. Thank you! ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ -->

Support plan

<!-- We are here to help!

Community based support is, by its nature, limited to available community members able to help. Most community support issues are resolved within 2 weeks. Before submitting an issue, please review the various support options available at https://hapi.dev/support/. That page includes useful information about different ways to ask questions. -->

  • is this issue currently blocking your project?: yes
  • is this issue affecting a production system?: no

Context

  • node version: 10.19.0
  • module version: 16.1.8
  • environment (e.g. node, browser, native): Node

How can we help?

<!-- Im trying to design a schema that will not two fields to have the value N. -->

const some = 'properly formatted code example';Joi.object({
   a: Joi.string()
        .when('b', { is: 'N', then: Joi.valid('Y'), otherwise: Joi.valid('Y','N') }),
    b: Joi.string()
  			.when('a', { is: 'N', then: Joi.valid('Y'), otherwise: Joi.valid('Y','N') })
})

I get the error below:

Error: item added into group b created a dependencies error

closed time in 21 hours

Enado95

issue commentsideway/joi

Check two fields have a same specific value and allow another value

Got it. I remove the condition from 'b' and change the condition on 'a' to invalid('N') to get my desired outcome.

Enado95

comment created time in 21 hours

issue commentsideway/joi

Check two fields have a same specific value and allow another value

@Enado95 Yeah because your 2 keys a and b are referring to each other.

Enado95

comment created time in 21 hours

startedarb/celebrate

started time in 21 hours

issue openedhapijs/hapi

ETags adjusted for "content-encoding" are not correct

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): probably not

Context

  • node version: any
  • module version with issue: 20.0.3
  • last module version without issue: none
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce?

Serve wellformed responses that won't corrupt the received payload.

const server = Hapi.server({ port: 4000 });
server.route({
    method: 'get',
    path: '/',
    handler(request, h) {

        const response = h.entity({ etag: 'abc' });
        if (response) {
            return response;
        }

        const total = 4000;
        const bytes = parseInt(request.query.i) || 100;
        const stream = new Stream.Readable({ read() {} });
        stream.setCompressor = (compressor) => {

            setImmediate(() => {

                let sent = 0;
                for (sent = 0; sent < total - bytes; sent += bytes) {
                    stream.push(Buffer.alloc(bytes));
                    compressor.flush();
                }

                stream.push(Buffer.alloc(total - sent));
                stream.push(null);
            });
        };

        return h.response(stream).type('text/html');
    }
});

server.start();

A test:

curl -H 'Accept-Encoding: gzip' 'localhost:4000/?i=500' -v | wc -c

ETag: "abc-gzip" Bytes: 110

When the same content is requested with different flushing the results are wrong:

curl -H 'Accept-Encoding: gzip' 'localhost:4000/?i=20' -v | wc -c

What was the result you got?

ETag: "abc-gzip" Bytes: 2013

What result did you expect?

I would expect both results to signal a weak ETag since the transferred bytes are not always identical. In this case that would be:

ETag: W/"abs"

While I expect most compressed responses are bytewise identical, this is not a guarantee and hapi should not expect this as the default.

created time in a day

push eventhapijs/hapi

Jonathan Samines

commit sha ea6d80e448ea52ece857b995b8f72d45817f2bf3

[fix-docs-links] Fix links to server.cache reference

view details

push time in a day

issue openedsideway/joi

Check two fields have a same specific value and allow another value

<!-- ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ You must complete this entire issue template to receive support. You MUST NOT remove, change, or replace the template with your own format. A missing or incomplete report will cause your issue to be closed without comment. Please respect the time and experience that went into this template. It is here for a reason. Thank you! ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ -->

Support plan

<!-- We are here to help!

Community based support is, by its nature, limited to available community members able to help. Most community support issues are resolved within 2 weeks. Before submitting an issue, please review the various support options available at https://hapi.dev/support/. That page includes useful information about different ways to ask questions. -->

  • is this issue currently blocking your project?: yes
  • is this issue affecting a production system?: no

Context

  • node version: 10.19.0
  • module version: 16.1.8
  • environment (e.g. node, browser, native): Node

How can we help?

<!-- Im trying to design a schema that will not two fields to have the value N. -->

const some = 'properly formatted code example';Joi.object({
   a: Joi.string()
        .when('b', { is: 'N', then: Joi.valid('Y'), otherwise: Joi.valid('Y','N') }),
    b: Joi.string()
  			.when('a', { is: 'N', then: Joi.valid('Y'), otherwise: Joi.valid('Y','N') })
})

I get the error below:

Error: item added into group b created a dependencies error

created time in a day

PR opened hapijs/hapi

Fix links references to server.cache
+2 -2

0 comment

1 changed file

pr created time in a day

issue closedhapijs/hapi

how do i handle errors with streams in hapi?

<!-- ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ You must complete this entire issue template to receive support. You MUST NOT remove, change, or replace the template with your own format. A missing or incomplete report will cause your issue to be closed without comment. Please respect the time and experience that went into this template. It is here for a reason. Thank you! ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ -->

Support plan

<!-- We are here to help!

Community based support is, by its nature, limited to available community members able to help. Most community support issues are resolved within 2 weeks. Before submitting an issue, please review the various support options available at https://hapi.dev/support/. That page includes useful information about different ways to ask questions. -->

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: v15.3.0
  • module version: 20.0.3
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information:

How can we help?

Using h.response(stream) with any stream does not seem to handle errors and instead just closes the connection without sending anything. I am wondering if hapi can/should do some error handling or how i can handle stream errors myself.

const hapi = require('@hapi/hapi');
const fs = require('fs')

const server = hapi.server();

server.route({
  method: 'GET',
  path: '/',
  handler(_, h) {
    const stream = fs.createReadStream('./doesNotExist');
    return h.response(stream);
  },
});

server.start()
  .then(() => console.log('Server running on %s', server.info.uri));

Test

❯ curl localhost:43951   
curl: (52) Empty reply from server

closed time in a day

fiws

issue commenthapijs/hapi

how do i handle errors with streams in hapi?

I'm going to close this as answered, but feel free to continue any discussion.

fiws

comment created time in a day

PR closed sideway/joi

floating point solution is added for multiple verification

It works incorrectly if either "value" or "base" variable is floating point number.

+14 -1

0 comment

1 changed file

TarikAkyuz

pr closed time in a day

PR opened sideway/joi

floating point solution is added for multiple verification

It works incorrectly if either "value" or "base" variable is floating point number.

+14 -1

0 comment

1 changed file

pr created time in a day

issue openedsideway/joi-date

Documentation missing

<!-- ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ You must complete this entire issue template to receive support. You MUST NOT remove, change, or replace the template with your own format. A missing or incomplete report will cause your issue to be closed without comment. Please respect the time and experience that went into this template. It is here for a reason. Thank you! ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ -->

Context

  • node version: All
  • module version: All

What are you trying to achieve or the steps to reproduce ?

The documentation on the hapi site is missing. If you click on the documentation link, it leads to a 404. See for yourself: https://hapi.dev/family/joi-date/

<!-- Before opening a documentation issue, please consider opening a Pull Request instead for trivial changes such as typos, spelling, incorrect links, anchors, or other corrections that are easier to just fix than report using this template.

Please do not spend valuable time proposing extensive changes to the documentation before first asking about it. We value your time and do not want to waste it. Just open an issue first using this template and ask if your proposed changes would be helpful.

Make sure to wrap all code examples in backticks so that they display correctly. Before submitting an issue, make sure to click on the Preview tab above to verify everything is formatted correctly. -->

created time in 2 days

more