hapijs

Hapi Lab why Test failed when all the tests are passed

人盡茶涼 提交于 2019-12-05 10:33:57
Does anyone know the meaning of ? npm ERR! Test failed. See above for more details. 3 tests complete Test duration: 873 ms The following leaks were detected:lr npm ERR! Test failed. See above for more details. I run my 3 tests I get a successful green 3 tests complete (all my test are passed) but why I also see the nasty ? npm ERR! Test failed. See above for more details. The test fails because lab detected a global variable leak: The following leaks were detected:lr This means you probably defined the lr variable somewhere as global. Try to find where you did that and make the variable local.

hapi.js - 404 route VS static files route

感情迁移 提交于 2019-12-05 00:53:20
I'm trying to migrate my Express app to hapi.js, and I having trouble with my routes. I just want 2 GET : my index '/', and everything that is not '/' to redirect to '/'. Using Express I had this: // static files app.use(express.static(__dirname + '/public')); // index route app.get('/', function (req, res) { // whatever } // everything that is not / app.get('*', function(req, res) { res.redirect('/'); }); I have issues with hapi.js to get the same behaviour. My "static road" looks like this: server.route({ method: 'GET', path: '/{path*}', handler: { directory: { path: 'public', listing: false

How to get the full URL for a request in Hapi

我是研究僧i 提交于 2019-12-04 23:01:00
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? The full URL isn't stored somewhere you can get it. You need to build it yourself from the parts: const url = request.connection.info.protocol + '://' + request.info.host + request.url.path ; Even though it might

Joi validation multiple conditions

╄→гoц情女王★ 提交于 2019-12-04 17:43:32
问题 I have the following schema: var testSchema = Joi.object().keys({ a: Joi.string(), b: Joi.string(), c: Joi.string().when('a', {'is': 'avalue', then: Joi.string().required()}) }); but I would like to add a condition on c field definition so that it is required when: a == 'avalue' AND b=='bvalue' How can I do that? 回答1: You can concatenate two when rules: var schema = { a: Joi.string(), b: Joi.string(), c: Joi.string().when('a', { is: 'avalue', then: Joi.string().required() }).concat(Joi.string

Hapijs using both Http and Https on one connection

▼魔方 西西 提交于 2019-12-04 15:37:41
问题 New to Hapijs and trying to use it to create an app that uses HTTPS for all requests and redirect HTTP to the secure connection.The problem is the app goes in HTTPS mode no problem but if i change the URL to HTTP the server does not respond and don't know the reason why. This is what i have came up with so far, it works but not for HTTP var connectionOptions = { port: 3000, tls: { key: fs.readFileSync(path.join(__dirname, 'key/key.pem'), 'utf8'), cert: fs.readFileSync(path.join(__dirname,

Hapi server on heroku fails to bind port

会有一股神秘感。 提交于 2019-12-04 08:21:37
I'm working on a Hapi server for a ReactJS app but when I try to deploy to Heroku, I get the R10 error "Failed to bind to $PORT within 60 seconds of launch". What is going on? I'm using process.env.PORT. I also tried parseInt() around it. Also tried disabling varying packages. The build is successful always. In the Heroku logs, I see the console log from the index.js ("Hapi running on ...") but then the R10 error shows up and the server restarts, then crashes. ==> 🌎 Hapi Production Server (API) is listening on http://localhost:14316 2016-01-22T15:10:33.947571+00:00 heroku[web.1]: Stopping

How to redirect from an xhr request

北战南征 提交于 2019-12-04 05:22:27
问题 When I send an xhr post request to my server. It replies with a 302 redirect, but I can only log the entire redirect html, and cannot get the browser to redirect to the new url. server.js const Hapi = require('hapi'); const Inert = require('inert'); const server = new Hapi.Server(); const port = 8888; server.connection({ port }); server.register([ Inert ], () => { server.route([ { method: 'get', path: '/', handler: (request, reply) => { reply.file('index.html'); } }, { method: 'get', path: '

Hapi nested routing

耗尽温柔 提交于 2019-12-04 00:19:59
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 something like this: server.route({ method: 'GET', path: '/projects', handler: getAllProjects }); server.route

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

旧街凉风 提交于 2019-12-03 23:08:23
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. So I found a way: server.events.on('response', function (request) { console.log(request.info.remoteAddress + ': ' + request

Download file from Amazon S3 using REST API

我与影子孤独终老i 提交于 2019-12-03 08:54:40
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: "/downloadFile", config: {auth: false}, handler: function (request, reply) { // TODO reply({}) } },