Tag: hapijs

Node.js在脚本之间传输数据

我正在Hapi框架中开发一个node.js服务器。 我采用了RabbitMQ(amqp)排列我的任务。 但是,一旦发送请求,不是立即回复请求,而是将消息发送到实际function所在的Rabbit服务器。 然后,用户应该返回结果给(请求,回复)函数并让函数回复它。 现在我的解决scheme是在我的工作文件(amqp使用者所在位置)创build一个variables并将其导出。 然后在索引文件(我的主要脚本与路由处理程序),我导入variables。 一旦收到一个请求,它会发送一个消息给RabbitMQ服务器,服务器将改变这个variables。 然后,回到索引文件,脚本更新variables的值,然后回复它。 显然,由于asynchronous,程序回复了以前请求的结果。 我做了一些研究,发现我们不应该在脚本之间共享一些variables。 有没有人有办法解决吗? 我的目标是,我可以把我的amqp消费者的脚本。 一旦我运行脚本,消费者将准备好接收任何相应的消息。 然后在我的索引文件中,一旦收到一个请求,就会发送一个消息给RabbitMQ服务器。 然后它应该抓住消费者的结果并回复它。 以下是我的代码: index.ts import * as Joi from "joi"; import * as amqp from "amqplib/callback_api"; import * as waitUntil from "wait-until"; import * as repository from "./repository"; import * as worker from "./worker"; // defien variables from internal modules let greeter […]

在nodejs应用程序中了解我的客户端IP

我有两层应用程序结构(Nginx(代理)+ nodejs(应用程序)。我需要在我的应用程序(nodejs)中获得我的客户端IP(谁访问我的网站)的结束。现在我的客户端IP,它正在login我的Nginx日志文件(通过启用下面的conf proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 现在我在我的应用程序服务器中获取Nginx服务器IP,但是我不想让我的Nginx服务器IP,而不是我需要在我的应用程序中获取我的原始客户端IP 这是应用程序代码,我们正在使用它来获取应用程序服务器中的客户端IP。 request.headers['x-forwarded-for'] || request.info.remoteAddress 哪里; Nodejs–> Happijs框架

Hapi.js身份validation不工作

这是我现在的代码这里的问题是,当我运行这个与Hapi版本14.xx或以下它对我来说工作完全正常,但是当我运行这与hapi版本15.0.1或更高,它给了我下面的错误。 身份validation过程中是否有任何更改? throw new Error(msgs.join(' ') || 'Unknown error'); ^ Error: Unknown authentication strategy UserAuth in /api/user/loginDetails at Object.exports.unique.exports.contain.exports.reachTemplate.exports.assert.condition [as assert] (F:\cbl\projects\lawn-mower\node_modules\hapi\node_modules\hoek\lib\index.js:736 :11) at internals.Auth.test.internals.Auth._setupRoute (F:\cbl\projects\lawn-mower\node_modules\hapi\lib\auth.js:144:14) 我正在使用的示例路线 { method: 'POST', path: '/api/user/loginDetails', config: { auth: 'UserAuth', handler: function (request, reply) { }, validate: { payload: { }, headers: UniversalFunctions.authorizationHeaderObj, failAction: UniversalFunctions.failActionFunction }, plugins: { 'hapi-swagger': […]

EJS布局在hapi.js中不起作用

hapi.js文档解释了如何使用布局 ,但是当我按照文档中的描述设置布局时,布局是在没有引入内容的情况下呈现的。 当我删除服务器布局configuration时,内容呈现正确(没有布局)。 这个应用程序使用vision ,这可能是一个angular色。 服务器 engines: { html: require('ejs') }, relativeTo: __dirname, path: 'templates', layout: true, layoutPath: 'templates/layouts', … 路线 handler: (request, reply) => { reply.view('test') 模板/布局/的layout.html <html> <body> {{{content}}} </body> </html> 模板/ test.html中 <h1>Test!</h1> 渲染的内容很简单: {{{content}}} 我怎样才能让内容在布局内呈现?

如何在hapi.js ejs布局中获得多个内容区域?

我想定义一个模板,在hapi.js中使用ejs在包含的布局中呈现信息。 例如: 的layout.html <html> <head> <title><%- contentFor('title') %></title> </head> <body> <%- content %> </body> </html> 的index.html contentFor('title', 'My title') <h1>My content</h1> 对我来说很重要,但是它的工作原理是,模板中定义了不同的布局内容,而不是在路由级别传入。 这可能吗?

Sinon假XML不捕获请求

我正在尝试使用Lab和Sinon来编写一些testing,用于在我的文件中调用的各种HTTP请求。 我遵循http://sinonjs.org/上的假XMLHttpRequest示例,但是当我运行我的testing时,似乎并没有实际捕获任何请求。 这是(相关的)testing代码: 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); }; done(); }); after(function (done) { // clean up globals xhr.restore(); done(); }); it('responds with the ticket id', (done) => { create(internals.validOptions, sinon.spy()); console.log(requests); // […]

如何填充request.auth.isAuthenticated一旦身份validation在HAPI框架中的后续路由?

server.ext('onRequest', (request, reply) => { request.context = { token: request.headers['X-ACCESS-TOKEN'] || request.headers['x-access-token'], clientId: request.headers['X-CLIENT-ID'] || request.headers['x-client-id'], }; request.reply(request.context) }); 当我调用request.reply时,会抛出错误。

如何在kibana中安装newrelic

我试图为我的kibana实例安装newrelic。 我得到的数据在newrelic但收到以下警告: Some modules were uninstrumented during the current time window: bluebird, hapi. Make sure require('newrelic'); is the first line of the application's main module. 我以为这是“应用程序的主要模块”,但显然不是。 我应该在哪里require('newrelic'); 在kibana代码来让它正常工作?

我试图连接到连接到我的SQL服务器数据库与节点和hapi.js

我正在尝试使用node和hapi.js来testing连接到我的sql服务器,并在我的一个表上运行一个简单的查询。 我对node和Hapi相当陌生,所以我只是想弄明白这一点 所以首先我的文件夹结构如下我有一个名为api的文件夹,其中有路线,这就是我在做我的路线get_aosdata.js这个作品我testing它只是传回'你好世界'然后我有一个查询文件夹下api这是我在connection.js中设置我的数据库连接 这是我的路线目前的样子 'use strict'; const query = require('../query/connection'); module.exports = { method: 'GET', path: '/api/query/{id}', config: { pre: [ { method: query.getSqlConnection, assign: 'db' } ], handler: (request, reply) => { const request = new db.Request(); request.query(`SELECT a.OrdNbr, a.sotypeid, a.user6, a.lupd_datetime, a.user3, a.crtd_user, a.S4Future01, a.slsperid, a.totmerch, a.CustOrdNbr from SOHeader a join customer b […]

如何使用数据库callback函数redirect用户 – HAPI

我希望我的用户被显示一个加载图标,直到数据库响应,然后被redirect到正确的页面。 我的代码是沿着的: // handler function handler(request, reply) { reply.view('loading') // show loading with css // do database stuff… // database callback function function db_callback_function() { reply.redirect('user/page') // after db responds, redirect. } } Hapi说我只能使用一次回复界面: Unhandled promise rejection (rejection id: 1): Error: reply interface called twice 那么如何在数据库加载后redirect我的用户呢? 编辑:我知道我需要使用前端显示加载器。 我只是不知道我的后端会告诉我的前端何时redirect。