Questions tagged [hapijs]

0

votes
0

answer
2

Views

HapiJS sending log messages to an HTTP point

We are using good-http to send messages using 'server.log('info', 'test message')'. This messages displays on the console but not sent to our http end point. When we debugged good-http we found out that only 'request.log(...)' based invocations reach Wreck.request line that's placed within good-htt...
Ramesh Mohan Reddy
1

votes
1

answer
133

Views

Expose hapi plugin methods via server.expose or server.method

We are using Hapi as our API framework and put everything related to our persistent storage backend (mongo via mongoose) in a plugin. Now I am wondering how to best expose all the CRUD methods for the different collections (users, notifications, purchases, etc.) to our other API plugins. I know abou...
Stephan Max
1

votes
2

answer
72

Views

How can I compose handler off Hapijs?

I need to do some additional authentication in a few of my handlers. Is there a way of doing that way in a composable way? export async function handler(request) { const user = request.auth.credentials; const customer = FindCustomer(user); if (!customer) { throw Boom.forbidden('user is not a custome...
sheki
1

votes
1

answer
1.5k

Views

How to return Hapi reply with promise and vo.js

I have an asynchronous nightmare.js process which uses vo.js flow control with a generator: vo(function *(url) { return yield request.get(url); })('http://lapwinglabs.com', function(err, res) { // ... }) This needs to return a promise to Hapi (v.13.0.0) with reply() interface. I have seen examples...
MachuPichu
1

votes
1

answer
127

Views

Where is the unresolved path of a Hapi Request?

Given this route config: server.route method: 'GET' path: '/app/usage/{id}' handler: (req, reply) -> ... Is there a way to programmatically get the unresolved path /app/usage/{id} from the request object in a prehandler? I know how to get the resolved path e.g. /app/usage/1234, but I would like the...
gburton
1

votes
1

answer
1.6k

Views

Calling server.inject() POST request not calling handler in Hapi.js

I have a Jasmine test spec test_spec.js like this: describe('my tests', () => { it('POST should return 201 created', () => { var req = { method: 'POST', url: '/api/v1.0/message', payload: JSON.stringify({name: 'Ethan'}) }; server.inject(req, res => { expect(res.statusCode).to.equal(201); }); }); });...
pkout
1

votes
2

answer
774

Views

Multiple auth schemes in hapijs?

I am building an application using hapi.js . The clients of this application are going to be either a web application, so authentication is via JWT in the coookie or via OAuth2 clients which are going to be sending the Bearer key header. Is there some way that the framework allows using both schem...
Padam J. Singh
1

votes
1

answer
125

Views

Routing with node

I am trying to understand how to build a Node.js project. I have followed a tutorial I found to make a chat app. The routing between the server side and the client side is not working. If you could explain to me why, or, maybe give me a good reference to understand how its all should work togeth...
bratibrat
1

votes
1

answer
242

Views

Add custom login form to hapi-auth-basic

I use hapi-auth-basic to authenticate users. My question is how to add custom login form instead of using the basic form of the browser.
becem wniss
1

votes
1

answer
489

Views

What is the best approach to test a HapiJS plugin, with Lab?

What is the best way to test a HapiJS plugin, for example one plugin that add routes and handlers. Since I have to create an instance of Hapi.Server to run the plugins, should I define all the tests from the app's root, for all the plugins ? or should I manage to get THE instance of Hapi.Server in...
acmoune
1

votes
2

answer
232

Views

HapiJS Catbox: How to search a key using some value's fields as search criteria?

In my app when a user is authenticated, I store his session data (including his email) in the server cache, and I create a sessionId that I use as the key. When a user is deleted from the database, I want to check if he was logged in, that is, if there is a session in the cache that comes from his a...
acmoune
1

votes
1

answer
79

Views

hapijs custom http status message

I have a requirement to set a custom HTTP Status message in hapijs application. How this could be done? My code is: 'use strict'; const Hapi = require('hapi'); const server = new Hapi.Server(); server.connection({ port: 3000, host: 'localhost' }); server.route({ method: 'GET', path: '/', handler: fu...
lospejos
1

votes
2

answer
995

Views

Redirect http to https in Hapi.js

I do have the following configuration for my hapi server const server = new Hapi.Server(); const tls = { cert: fs.readFileSync(path.join(__dirname, '../certificates/cert.crt')), key: fs.readFileSync(path.join(__dirname, '../certificates/cert.key')), }; server.connection({ port: process.env.PORT_HTTP...
Alexandru Olaru
1

votes
1

answer
64

Views

validating sub-params dependent on parent params with Joi and Hapi

How can I implement validation for something like the following logic for query params: if (type is 'image') { subtype is Joi.string().valid('png', 'jpg') else if (type is 'publication') { subtype is Joi.string().valid('newspaper', 'book') to get either server/?type=image&subtype=png or server/?type...
punkish
1

votes
1

answer
229

Views

Remove the parent element from JSON reply

I have a route used for AJAX calls. It gets items from a DB and returns a JSON array. I'm using: return reply({ myArray }).code(200); Everything works but my output in the browser is: { 'myArray':[ { '_id':'1', 'name':'Asd1' }, { '_id':'2', 'name':'Asd2' } } But what I need is: { [ { '...
daliz
1

votes
1

answer
586

Views

hapijs Joi when one field is non empty other fields must be required

When the password is non empty means other two fields are required. In some cases password will be present but that will be null, on that cases other two fields are not required. I tried with exist() and !empty() but it doesn't work. password : joi.string().trim().optional().description('Passwo...
Sivabalan
1

votes
1

answer
324

Views

Large file upload fails on node.js Hapi

I have a node.js script which should handle file uploads, also multiple at once. Uploading pictures and voices work just fine. However, video files at around 10 MB or larger do not upload. Sometimes it doesn't work at all and sometimes it gets stuck in the fs.writeFile function. Maybe there is a bet...
Robin Betka
1

votes
1

answer
891

Views

hapi 17 with joi validation AssertionError

I'm porting an existing Hapi 16 app to Hapi 17 - and have run into problems with Joi validation... 'use strict'; const Joi = require('joi'); const validator = Joi.object({ 'sku': Joi.string().required(), 'name': Joi.string() // cut for berevity.. ) }) module.exports = { method: ['POST', 'PUT'], path...
Rob
1

votes
1

answer
268

Views

Hapi js API basic authentication error

I was researching about the hapi js API basic authentication and i'm using Hapi documentation about the authentication. I believe i did everything right but i'm getting following error saying about UnhandledPromiseRejectionWarning. Please help index.js 'use strict'; const Bcrypt = require('bcrypt')...
Ramitha Rupasinghe
1

votes
1

answer
338

Views

node-oracledb error when executing stored procedure NJS-012

I'm running Node 8.9.4, Hapi 17.4, and Oracledb 2.2. When attempting to call a stored procedure, I get the error 'NJS-012: encountered invalid bind data type in parameter 2'. Nothing I've been able to do seems to fix the issue. The code that calls the procedure is: async function getSavedViews(req...
Andrew Cooper
1

votes
1

answer
27

Views

Catching plugin issues in hapi 17

I'm using hapi17 and building a simple plugin wrapper around pg (https://node-postgres.com for access to Postgresql). I suspect I am making a simple Javascript-noob error here, but I can't quite figure where. My plugin code looks like this: 'use strict'; const {Pool} = require('pg'); exports.plugi...
Little Code
1

votes
2

answer
320

Views

Hapijs server start error - Invalid server options

I copied this simple server program const Hapi = require('hapi'); const server = new Hapi.Server({ host: 'localhost', port: 8080, }); server.route({ path: '/', method: 'GET', handler: (request, response) => { response(true); }, }); server.start(() => { console.log('Server running at:', server.info.u...
Aakash Verma
1

votes
1

answer
1.4k

Views

Authentication strategy simple uses unknown scheme: bearer-access-token

I am using hapi-auth-bearer-token plugin for my api authentication using hapijs. here is my code: apiServer.register(require('hapi-auth-bearer-token'), function (err) { server.auth.strategy('simple', 'bearer-access-token', { allowQueryToken: true, // optional, true by default allowMulti...
user3311522
1

votes
1

answer
723

Views

How to call Hapi Plugins for certain routes?

Im using Hapi 12.1. Trying to figure out how to call certain extension points only on certain routes. For example for : '/hello' I want to call three different extension points that work on the 'onRequest' step. For: '/goodbye' I want to call a different extension point that works also on the 'onRe...
Matthew Drooker
1

votes
2

answer
4.1k

Views

How can I add a url query param to a hapi proxy call in hapijs

supose I want to add a query param to this call to google, but coding it instead of doing a forward from the http call I'm using nodejs hapi framework server.route({ method: '*', path: '/{p*}', handler: { proxy: { host: 'google.com', port: 80, redirects: 5 } } }); Is posible to modify the url...
edwinallenz
1

votes
2

answer
595

Views

How to connect CouchDb with HapiJs?

I have an App written using the HapiJs framework for Node and want to connect it to a CouchDb databse, but am having trouble finding the code to do so. Can anyone help me with the code to do that? What is the 'normal' way of doing that? Cheers!
hyprstack
1

votes
1

answer
1.9k

Views

joi validation: Set minimum array length conditionally

I have an array field which i would like to ensure that it has at least one element when a condition is met: genre:Joi.array().includes(data.genres).when('field'{is:'fieldValue',then:Joi.required()}) If i changed the 'then' field with Joi.required().min(1), it complains. Can i do this with Joi?
user2468170
1

votes
2

answer
264

Views

does hoek (hapijs) transform() handle arrays?

Following the transform() example on the Hoek documentation, is there a way to transform arrays in the source object? turning the example into something with an array, like this: var source = { address: [ { one: '123 main street', two: 'PO Box 1234' }, { one: '456 fake street', two: 'Apt 2b' }], tit...
Marc Smith
1

votes
1

answer
4.6k

Views

Hapi.js file upload how do I grab the file so I could use imageMagick command line tool on it

I changed the code to output a file instead of a stream. IT provides me the the tmp path and when I use fs.readFile the data when converted to string is fileUpload=Resume_BrianInoa.pdf I am posting a file to hapijs server this is my route handling the post: server.route({ method: 'POST', path: '/co...
inoabrian
1

votes
1

answer
814

Views

How do I render a view to a variable with Hapi?

Is there a way to render a view to a variable? I want to change this. var events = { lastIndex: 32, payload = [ { id: 5, title: 'Hello world!' conyent: 'Lorem ipsum' }, { id: 7, title: 'Hello world!' conyent: 'Lorem ipsum' }, ... { id: 32, title: 'Hello world!' conyent: 'Lorem ipsum' } ] }; return r...
Sergio Flores
1

votes
1

answer
486

Views

Handlebars Template Doesn't Display Data

My Handlebars template: {{#each .}} {{this}} {{title}} {{author}} {{/each}} Partial Data Example: [ { title:'How We Solve Big Problems By Thinking Small', link:'http://product.hubspot.com/blog/how-our-product-team-thinks-small-to-solve-big-problems', published:'2015-03-05T13:30:00.000Z', author:'jbo...
program247365
1

votes
2

answer
1.4k

Views

How to capture callback from failed validation in Joi

We're building a web service using Hapi. Our routes have some validation. I was wondering if it was possible to capture or override the default callback on failed validation, before or after hapi replies to the client. my (non-working) code: { method: 'GET', config: { tags: tags, validate: { params...
Frederic Charette
1

votes
3

answer
1.3k

Views

Validate REST parameters using Joi in Nodejs

I am trying to validate my GET request in a Hapi Node server by using joi package. The Validation is working correctly as expected. However I am struggling to find a way to return an error if there are no parameters passed. Currently if there are no parameters passed it succeeds. Also is there a way...
user1692342
1

votes
1

answer
2k

Views

Returning error object along with the hapijs boom object

I'm trying to return the error object inside the response of a boom internal error object but it keeps omitting the error object. I tried to follow the answer here but it didn't help. function (request, reply) { options.healthCheck(function (err) { if (!err) { return reply('I\'m healthy!!!'); } var...
idoshamun
9

votes
1

answer
104

Views

Extract validation rules from a route

I am trying to build an endpoint like this /schema?method=get&endpoint=/users/search and the purpose is the provide a 'JSONified' representation of the Joi validation I'm using. This will be used by the Front-End for client-side validation. Is this even possible? Printing server.table() doesn't seem...
Cybrix
9

votes
4

answer
908

Views

How to return an array of errors with graphQL

How can I return multiple error messages like this ? 'errors': [ { 'message': 'first error', 'locations': [ { 'line': 2, 'column': 3 } ], 'path': [ 'somePath' ] }, { 'message': 'second error', 'locations': [ { 'line': 8, 'column': 9 } ], 'path': [ 'somePath' ] }, ] On my server, if I do throw('an er...
Lev
1

votes
1

answer
2.4k

Views

Which is the structure of the path in the case of query request?

I'm using hapi.js but one thing is not clear for me. In the case I make api request passing params in the path, I could get these ones by calling request.params in the handler. When I do request in the form of query what should be the path? In the first case I place in the path property something...
Mazzy
1

votes
2

answer
632

Views

Better console output in HapiJS?

I feel like I'm missing something basic, but I can't work out how to get better console output in HapiJS. I am writing an API, and at the moment when there is an error it prints out. 150516/063815.663, [response], http://localhost:3000: post /users{} 500 (120ms) And returns a response saying 'there...
jonobattle
1

votes
1

answer
925

Views

request.auth.session.set(user_info) not working HapiJS

This is my strategy, which is defined on a server.register(). I'm basing my work off a tutorial and it is literally copied from it but it doesn't work. server.auth.strategy('standard', 'cookie', { password: 'somecrazycookiesecretthatcantbeguesseswouldgohere', // cookie secret cookie: 'app-cookie', /...
Forget
1

votes
1

answer
1.3k

Views

How can I get the buffer of the raw request body in Hapijs?

It's okay with using body-parser + expressjs. But my problem is: how can I get the buffer of the raw request body in Hapijs? The thing I am talking to is like the buf param in this function of body-parser npm package: verify(req,res, buf, encoding) I need it for this function in messenger-platform-s...
Dylan Dang

View additional questions