Questions tagged [hapijs]

1

votes
1

answer
149

Views

Sequelize | Return results if either hasMany association matches their where conditions

I have model A, B, and C. A has a hasMany association to B & C ( and B & C have a belongsTo association back to A ) I want to return records of A where B.b_column = 'b' OR C.c_column = 'c'. My current approach was to trying using the required: false in the where's but that just returns all the rec...
ndyr
1

votes
0

answer
499

Views

How to remove all/single event listners in socket.io

I am using socket.io for realtime functionality in my app with hapijs. When I am trying to add a listner on server side in a hapijs route and if I reload the same route/page 10 times or more then it starts showing me an error (node:9004) MaxListenersExceededWarning: Possible EventEmitter memory leak...
Dimpal Singh
1

votes
0

answer
51

Views

How to pass the values for the hapijs handler to the nextjs page

I have started the nextjs for a week ago for my admin panel. I want to integrate the nextjs with hapijs. I followed the example of custom server routing in the url https://github.com/zeit/next.js/tree/canary/examples/custom-server-hapi But I don't know how to pass the values from the hapi handler t...
Sivabalan
1

votes
1

answer
45

Views

I want to send something in a POST command, without the user entering that value in Javascript

I am using mongoDB and Hapi to create a REST API. I am trying to be able to pass info into the database from the program itself. For example, I have a payload that is configured as so: config: { validate: { payload : { var_a: Joi.string(), var_b: Joi.number(), var_c Joi.string(), var_d: Joi.string(...
G. Curbelo
1

votes
1

answer
117

Views

hapi js api design joi validate error

While designing hapi js API with mongoose, facing issue with designing the joi validation for nested schemas. I am a newbie please help with the error models/ vahana.js var mongoose = require('mongoose'); var Schema = mongoose.Schema; var vahSchema = new Schema({ vehRegNumber: { type: String, requir...
jinks
1

votes
0

answer
58

Views

hapi-auth-cookie not overwriting default tll

I am using the plugin for an API REST using hapi 16.6.2 and hapi-auth-cookie 7.0.0. I set the keepAlive : true in the plugin initialization. In the login controller I have a 'remember me' parameter which sets the ttl (request.cookieAuth.ttl) for 15 days. This is not posible as the keepAlive function...
Anto S
1

votes
0

answer
52

Views

how to provide json string as payload while testing through npm Lab

I have a post route which accepts string. Here the input is JSON as string so I convert that string to JSON using JSON.parse() in my route logic. Now when I am testing it using Lab how can I give JSON string as payload. Code; lab.test('dummy test', done => { const options = { method: 'POST', url: '/...
Anil Kumar R
1

votes
0

answer
182

Views

Validate incoming data with unique check from database in hapijs with JOI

Is there any way in which I can validate API parameter with JOI plugin which can check uniqueness with database field. For example we can validate any parameter or incoming data in Laravel with specific validation rules as given below. 'email' => 'unique:users,email_address' Name of table: users N...
Jitendra
1

votes
2

answer
93

Views

promise execution with condition

I have a following promise function function run(args) { return new Promise(function(resolve, reject) { //logic }); } I want to pass an argument to the promise function run and on the returned value I want to have some condition, if it satisfies I want to pass one set of argument to the promise and...
Jedidiah Jeyaraj
1

votes
0

answer
55

Views

Using hapijs as an express middleware

Is there a way to add hapi as a middleware in an express app? It could work like so: var app = express(); var api = hapi.Server(); app.use('/api', api.expressHandler); app.get('/', renderHandler);
Arkanoid
1

votes
0

answer
350

Views

Joi required dynamic key

I am using Joi 10.6.0 in a Typescript project to validate the payloads on a series of requests. I am having the weirdest issue while validating a dynamic key in the payload: validate: { payload: Joi.object() .pattern(/^id_[\s\S]*$/i, Joi.string().required()) .keys({ state: Joi.string().optional(), p...
Barbara Jacob
1

votes
0

answer
34

Views

HAPI POST endpoint startup

I need to integrate some web-hooks into an existing VUE.js website to display some logs on the site. It will POST the data to an endpoint and then will be displayed on a page. I have used Hapi.js to create a basic POST endpoint to receive the data. However i need to start server.js (server logic)...
user685590
1

votes
0

answer
148

Views

How to set access-control-allow-origin even for 404 with HapiJs?

I have my HapiJS server configured as : const server = Hapi.server({ host: env.HOSTNAME, port: env.PORT, routes : { cors: { origin: ['ignore'], headers: ['Accept', 'Authorization', 'Content-Type'], } } }); Example of a route : GET /api/v3/users { cors: { origin: 'ignore', headers: [ '*' ] }, valida...
BastienSander
1

votes
0

answer
111

Views

NodeJs related to Hapi.js bug - SyntaxError: Unexpected identifier

I'm working on rendering the basic starting 'Hello, world' view of my Nodejs project based on the MVC model in this tutorial. However, I couldn't believe after I wrote down bunches of js scripts, I tested with running the server script with node server.js, I kept getting this error as in the screens...
Goldie
1

votes
1

answer
140

Views

HapiJS - MySQL: Query successful but postman returns Internal server error

I am trying to create an authentication system using Hapi and MySQL, I am testing it using postman, and I am also logging the output of the query on the terminal console. The thing is, the console outputs the query successfully, however, postman returns An internal server error occurred, and the con...
edargham
1

votes
0

answer
230

Views

Hapi.js 17.xx: How to return response from handler function without returning

In Hapi.js 17.xx, how would you return a response from Hapi.js handler function, without returning that response from the handler function directly? Rather than: handlerFunction(req, h) { return h.response(true).code(200) } Can you do something like: function callSomeFunction(req, h) { // Do someth...
Kainan
1

votes
0

answer
93

Views

Node / HAPI: Too many simultaneous connections causes network connections to be reset

A Node server uses HAPI to create its REST api. A growing number of connections is targetting this system until the point where more & more connections are 'reset', causing an error on the client side. First attempt was to look for synchronous ('blocking'?) request handlers, but everything requiring...
Jem
1

votes
3

answer
308

Views

Is there a way to restart node server in runtime?

I am trying to define an endpoint in my express server that whenever this end point is called, the server restarts automatically in runtime. for example, using express my server would look something like this ... var express = require('express') var app = express(); app.post('/restart', (req,res)=>...
Oss
1

votes
0

answer
109

Views

hapijs h2o2 protocol not supported

I have a webserver using https that uses h2o2 to proxy /api/* requests to my api server which uses http. Both servers are built on the HapiJS framework. From the /login page, a user can submit authentication data to /api/authenticate, from which it returns a JWT cookie and (what I'm stuck on) redire...
annon
1

votes
0

answer
239

Views

Uncaught (in promise) DOMException: Registration failed - push service error

I am trying to send push notifications to mobile users when a button is clicked. I can receive such notifications on the desktop, but when I use chrome emulator on the mobile device, I get 'Uncaught (in promise) DOMException: Registration failed - push service error'. The button I'm talking about tr...
xplorer1
1

votes
1

answer
362

Views

Array of objects with different schemas - JOI

I currently have the following schema on my app: Joi.object().keys({ users: Joi.array().items(mySchema) }) So I can get an array of users and validate them. But now I need different schemas for each object. Is there a way I can do something like: Joi.object().keys({ users: [ Joi.object().keys(mySch...
Yuri
1

votes
1

answer
324

Views

How to get the original input using Joi.raw()

I'm trying to validate some input with hapijs/joi and joi-date-extensions . I write this code example1.js: const BaseJoi = require('joi'); const Extension = require('joi-date-extensions'); const Joi = BaseJoi.extend(Extension); const schema = Joi.object().keys({ start_date: Joi.date().format('YYYY-M...
para 008
1

votes
0

answer
73

Views

Correlate database calls with incoming HTTP request using TypeORM and node.js/Hapi

I'm using TypeOrm (SQL Server) and hapi.js. I've created a custom logger and would like to log a pre-existing correlation ID when I log information about the query. The correlation ID is currently set on a request header in the incoming request. The docs show an example where request information can...
Craig Smitham
1

votes
0

answer
211

Views

Joi Regex is not recognized as Regex Pattern

I'm trying to make a validation rule for password field that it should consists of the following: Must have a number Must contain at least one upper-case Must contain at least one lower-case Must contain any of the following symbols [@$!] Should be at 8 to 20 characters only. Here's the regex patte...
Ricardo Raz
1

votes
0

answer
51

Views

Example of http2 connection coalescing in Node.js

I've searched all over for any code example (using any API framework) with Node.js that shows the HTTP/2 connection coalescing feature (In HTTP/2 requests for assets across different hostnames can be made over a single connection). For instance: an example that requests 2 assets from 2 different dom...
Yodim Yodot
1

votes
0

answer
38

Views

Defining Auth strategy using Glue

I am using glue to spin up the hapi server so I gave the json object with connection and registration details. I have 10 routes and i need to use authentication strategy for all the 10 routes, So followed the below steps 1) I have registered the xyz custom auth plugin 2) Defined the strategy server....
Anil Kumar R
8

votes
2

answer
142

Views

How to define socket variable globally

I have this piece of code in my socketio file and here I can use socket simply. import _ from 'lodash' import mongoose from 'mongoose' exports.register = (server, options, next) => { var io = require('socket.io')(server.listener) io.on('connection', async(socket) => { // here I can use socket.emit()...
Profer
1

votes
0

answer
33

Views

Server.methods and module

We are migrating from an architecture sharing code through server.methods to a more classic one based on modules. Doing that, we are facing a new issue. We cannot easily access server.methods from modules and so, we cannot use the cache system attached to them. How should I organize the code ? Shoul...
Ernest Jones
1

votes
0

answer
47

Views

hapi.js: How to retrieve a very large dataset from MongoDB as a stream and then pipe that data to the response

I am using hapi.js v17.2.0 and mongo driver v3.0.6. I need to retrieve data from MongoDB (possibly tens of millions of documents) in the form of a stream and then pipe that data to the response as each chunk of data comes in from Mongo. I have been looking all over and reading everything I can find,...
Samuel Earl
1

votes
1

answer
38

Views

Extend Joi with a custom type for populated strings

I want to create a custom Joi type for populatedStrings by using .extend(..) to create a type based on joi.string() which: Trims the string Changes the value to undefined if the trimmed string === '' so the validated output won't contain the key at all Overrides .required() so it acts on the trimmed...
bonzaibanzai
1

votes
0

answer
54

Views

NPM Error when installing napi-js or @adonis/cli

I am getting an error when i tried to install adonis cli or hapi-js. It is difficult to tell why am I getting this error on my system, maybe you guys have a hit or an idea. npm --version 6.8.0 node --version v10.14.2 This is the error when installing hapi-js sudo npm i -g napi-js node-pre-gyp WARN...
freecks
1

votes
0

answer
17

Views

Using the lab context helper for HapiJS causes an error

I wrote a unit test for HapiJS using lab beforeEach(async ({ context }) => { context.server = new Hapi.Server(); await context.server.register(Inert); }); test('/ rootPath is served', async ({ context }) => { await context.server.register({ plugin: require('../server/statics'), options: { rootPath }...
Peter
1

votes
1

answer
565

Views

In Node.js, how would you write a unit test page speed?

I'm working on a site replatform/redesign. We are going to use Node.js and Hapi. I would like to add unit test that will measure page load speed. Is there a way to do this using Mocha and Chai? Are there any frameworks that are dedicated to page speed testing specifically?
1

votes
1

answer
376

Views

Import only once a plugin in hapijs and use it everywhere

I should use a plugin named hapi-mongoose-db-connector into my hapijs application. In the repository page the developers suggest the ways you can import correctly it. It says that the following way is the bad way: # from the server mongoose = server.pack.plugins['hapi-mongoose-db-connector'].mongoos...
Mazzy
1

votes
1

answer
504

Views

Hapi.js Content Negotiation

I want to do content negotiation in my hapi routes to I can return the type of data my client can accept. With express I would do somthing like this res.format({ 'text/plain': function(){ res.send('Text Response'); }, 'text/html': function(){ res.send('HTML Response'); }, 'application/json': functio...
giodamelio
1

votes
1

answer
1.1k

Views

Using Hapijs and Bell with twitter provider. How to handle the authorize rejection from Twitter using the Bell module?

I'm using the Hapi framework (nodejs) with the Bell module, working with the Twitter provider. It was pretty simple to get a working code with the example given in the github page. I access the /login route and I get redirected to Twitter, where I authorize the app and then I'm redirected back to /...
Tony
1

votes
1

answer
537

Views

Using Hapi.js run a third party command line tool

In my application I need to use a command line tool but I have not seen any way to do it without using a npm module. I am using core node except for the command line tool.
inoabrian
1

votes
1

answer
821

Views

Node JS / Hapi image upload and security

Like many webservices, we need to get our visitors' profile picture. This is done through a simple hapi upload script. We are now wondering what are the best practices to prevent us from getting a malicious image that could contain a script to be executed directly or through a vulnerability. What is...
Charaf
1

votes
1

answer
336

Views

Hapi Swagger skip certain endpoints

Since the npm module hapi-swagger doesn't support file upload endpoints I need a way to skip certain endpoints in my tests. I've checked the docs and there's no beforeEach or any way to check which endpoint is which during the test runs. Currently I've just got my environment set to TEST and have an...
Dave Mackintosh
1

votes
1

answer
2.1k

Views

HapiJS Proxy Trouble

TL;DR How do I intercept a request, ping a different route for an ID, store the ID in a session, then continue the original request (especially PUT/POST with payloads) using the ID I just got? Background I am using HapiJS (8) to proxy requests from the client to an existing API (where I have no cont...
Nick Johnson

View additional questions