hapijs

How to get the full URL for a request in Hapi

笑着哭i 提交于 2019-12-22 01:39:56
问题 In my hapijs app, given a Request object, how can I find the original, unparsed, unmodified URL? function getRequestUrl (request) { return ...; // What goes here? } I've found that I can piece it together somewhat from Request.info.host , Request.path , and Request.query , but it lacks the scheme (ie, http vs https), and is a bit of a kludge. Isn't the plain URL available somewhere? 回答1: The full URL isn't stored somewhere you can get it. You need to build it yourself from the parts: const

Hapi nested routing

我怕爱的太早我们不能终老 提交于 2019-12-21 07:13:31
问题 Suppose I want to have REST endpoints which look roughly like this: /projects/ /projects/project_id /projects/project_id/items/ /projects/project_id/items/item_id CRUD on each if makes sense. For example, /projects POST creates a new project, GET fetches all projects. /projects/project_id GET fetches just that one project. Items are project specific so I put them under project_id, which is a particular project. Are there any way of creating this kind of nested routes? Right now I have

Download file from Amazon S3 using REST API

折月煮酒 提交于 2019-12-21 02:48:20
问题 I have my own REST API to call in order to download a file. (At the end, the file could be store in different kind of server... Amazon s3, locally etc...) To get a file from s3, I should use this method: var url = s3.getSignedUrl('getObject', params); This will give me a downloadable link to call. Now, my question is, how can I use my own rest API to download a file when it comes from that link? Is there a way to redirect the call? I'm using Hapi for my REST server. { method: "GET", path: "

Why does my ES6 (using Babel) class say `this` is undefined in an instance method?

二次信任 提交于 2019-12-20 20:28:08
问题 I am building an application in Node using Hapi.JS. I have a class for an authentication plugin that is giving me all sorts of problems. When I attempt to reference this from within a method on the class, I get an error saying that this is undefined. Why is this happening? An excerpt: class OAuth { constructor () {} register (server, err, next) { this.server = server; this.registerRoutes(); } registerRoutes () { console.log(this.server.route); this.server.route([ { method: 'POST', path: '

Why does my ES6 (using Babel) class say `this` is undefined in an instance method?

孤街浪徒 提交于 2019-12-20 20:28:08
问题 I am building an application in Node using Hapi.JS. I have a class for an authentication plugin that is giving me all sorts of problems. When I attempt to reference this from within a method on the class, I get an error saying that this is undefined. Why is this happening? An excerpt: class OAuth { constructor () {} register (server, err, next) { this.server = server; this.registerRoutes(); } registerRoutes () { console.log(this.server.route); this.server.route([ { method: 'POST', path: '

How to log all requests made to a hapi server without using a logging library?

跟風遠走 提交于 2019-12-14 00:18:26
问题 I'd like to see a nice log with short info about each request to my server, for use during development. I've seen the documentation on http://hapijs.com/api#request-logs, but I couldn't understand enough of it to get it working. What should I pass as the config object when I create the server? Should I then listen to events and log them or does it happen automatically? How do I log all the requests, and not just the errors? I'd like to avoid installing logging libraries. 回答1: So I found a way

How to get a Twilio SMS body text in Node.js

旧时模样 提交于 2019-12-13 04:06:29
问题 I'm working on a side-project of mine which integrates with Twilio. It's a Node.js app running on the Hapi.js framework. I have the app set up with Twilio so that when I text my Twilio number, Twilio gets the request from my app's route and texts me back with a static message in the response. What I'm having trouble with is getting the SMS body from the user's text. Let's say that I text the Twilio number with a word like banana I want to be able to retrieve that from the request so that I

JavaScript OAuth2 flow for Azure AD v2 login does not give an access_token

可紊 提交于 2019-12-13 03:44:25
问题 I'm using bell and hapijs and trying to get the office365 provider to work, but it seems like the https://login.microsoftonline.com/common/oauth2/v2.0/token endpoint isn't giving me the access_token required for getting profile information. This is the OAuth 2.0 flow I'm seeing: First it redirects to https://login.microsoftonline.com/common/oauth2/v2.0/authorize ?client_id=[client-id] &response_type=code &redirect_uri=http%3A%2F%2Flocalhost%3A5430%2Fapi%2Fv1%2Flogin%2Fazure-ad &state=[state]

How to register hapi cron with the latest version of hapi.js

大城市里の小女人 提交于 2019-12-13 02:55:40
问题 I have my server registered with hapijs. Here is my index.js composer((err, server) => { if (err) throw err server.initialize((errInit) => { if (err) throw errInit const register = (hapiRaven, options, next) => { return next() } register.attributes = { name: 'hapi-raven', version: '1.0.1', options: { } } server.register([ register ]) server.start(() => { // server starts }) }) }) I have to use hapi-cron and need to call an api with it for every minute. So I need to know where I can use below

Hapi Lab - how do I have shared state between lab experiments

微笑、不失礼 提交于 2019-12-13 00:15:20
问题 So I made up the user domain and I've done I think a good suite test it's like this: var Code = require('code'); var Lab = require('lab'); var lab = exports.lab = Lab.script(); var server = require('../../'); var Jwt = require('jsonwebtoken'); var Nconf = require('nconf'); var apiConfig = Nconf.get('api'); lab.experiment('Users', function () { var userId, payload, decoded, token; lab.test('create joi required', function (done) { var options = { method: 'POST', url: '/api/users', payload: {