hapijs

Does hapijs have something like overload protection?

隐身守侯 提交于 2019-12-10 19:33:01
问题 What will a hapi server do if it is overloaded and is there something like toobusy-js to prevent a fallout of the server by shortcutting some requests with errors. 回答1: Yes it's embedded in the framework, look at load on connections settings. You have 3 options : maxHeapUsedBytes - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). maxRssBytes - maximum process RSS size over which incoming requests are rejected

Server rendered React component class name automatically changed causing styling issue

扶醉桌前 提交于 2019-12-10 18:19:30
问题 I am using React 16 in my personal project (https://github.com/sachinjha1/react-redux-hapi-fullstack-starter/blob/master/package.json). I implemented SSR which works fine on my local. When i test the same app on Heroku all my styling are missing. When i did view source of server rendered html then i noticed that class names are different when rendered from Heroku. Heroku App URL -> https://raxpi.herokuapp.com/ In above heroku url in browser if you check view source you can see that class

How to post an array of objects with Chai Http

筅森魡賤 提交于 2019-12-10 15:57:59
问题 I'm trying to post an array of object with ChaiHttp like this: agent.post('route/to/api') .send( locations: [{lat: lat1, lon: lon1}, {lat: lat2, lon: lon2}]) .end (err, res) -> console.log err, res It returns an error as below: TypeError: first argument must be a string or Buffer at ClientRequest.OutgoingMessage.end (_http_outgoing.js:524:11) at Test.Request.end (node_modules/superagent/lib/node/index.js:1020:9) at node_modules/chai-http/lib/request.js:251:12 at Test.then (node_modules/chai

How to use PassportJS with HapiJS

五迷三道 提交于 2019-12-10 13:03:26
问题 I'm having a hard time to decide the best way to use PassportJS with HapiJS. Have anyone done that? I'm not talking about Travelogue because I kinda didn't like the way it works. Maybe I'm not using it right. 回答1: Travelogue has recently been "retired". Check out the replacement module bell. bell is much more "hapi-like" because it doesn't try to use passport.js 来源: https://stackoverflow.com/questions/22425792/how-to-use-passportjs-with-hapijs

hapi route joi validation of password confirmation

不问归期 提交于 2019-12-10 03:59:37
问题 How do I check that password and password_confirmation are the same ? var Joi = require('joi'), S = Joi.string().required().min(3).max(15); exports.create = { payload: { username: S, email: Joi.string().email(), password: S, password_confirmation: S } } 回答1: You can use Joi.any().valid() with Joi.ref(): password: Joi.string().min(3).max(15).required(), password_confirmation: Joi.any().valid(Joi.ref('password')).required().options({ language: { any: { allowOnly: 'must match password' } } }) 来源

HapiJS global path prefix

ぐ巨炮叔叔 提交于 2019-12-10 01:48:08
问题 I'm writing an API on HapiJS, and wondering how to get a global prefix. For example, all requests should be made to: https://api.mysite.com/v0/... So I'd like to configure v0 as a global prefix. The docs (here) don't seem to mention it -- is there a good way to do this in HapiJS? 回答1: If you put your API routing logic inside a Hapi plugin, say ./api.js : exports.register = function (server, options, next) { server.route({ method: 'GET', path: '/hello', handler: function (request, reply) {

Chrome doesn't send cookies after redirect

六月ゝ 毕业季﹏ 提交于 2019-12-09 18:10:19
问题 In node.js (using Hapi framework) I'm creating link for user to allow my app reading user account. Google handles that request and asks about giving permissions. Then Google makes redirect to my server with GET parameter as a response code and here I have an issue. Google Chrome isn't sending cookie with session ID. If I mark that cookie as a session cookie in cookie edit extension, it is sent. Same behavior in php, but php marks cookie as session when creating session, so it isn't problem. I

Call a hapi route from another route

北城余情 提交于 2019-12-08 20:29:32
问题 I am pretty new to HapiJS. I am building a service where I have two routes /route1 and /route2 both are using the plugin architecture. I have registered both as plugins on my manifest file. I want to call /route1 from /route2 so /route2 depends on the payload reply from /route1. I've been looking at putting the logic of /route2 on /route1 on the pre-handler but I want to keep them separately. Don't know how to call a registered plugin from another the thing is that both plugins (routes) are

How to define socket variable globally

好久不见. 提交于 2019-12-08 18:55:06
问题 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() and all }) next() } exports.register.attributes = { name: 'socket' } Now, I need to use the io socket to emit events from various files and don't want to connect this io.on('connection', async

Sinon Fake XML Not Capturing Requests

拥有回忆 提交于 2019-12-08 07:33:07
问题 I'm trying to write some tests using Lab and Sinon for various HTTP requests that are called in a file of mine. I followed the Fake XMLHttpRequest example at http://sinonjs.org/ but when I run my tests it appears to not actually capture any requests. Here is the (relevant) testing code: context('when provided a valid payload', function () { let xhr; let requests; before(function (done) { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = function (req) { requests.push(req); };