小编Ger*_*osi的帖子

有没有办法查看Hapi服务器中的所有路由

我们正在开发一个node.js Hapi服务器,该服务器从MongoDB数据库中提取路由列表并设置所述路由以进行服务.这样,由于数据库中的路由条目重复,服务器可能会失败.

我试过看,但未能找到一种方法来检查Hapi中的重复路线.

是否有可能获得Hapi服务器当前服务的路由列表?

在尝试构建来自MongoDB的路由时,是否可以进行错误检查,使其比标准的try/catch块更漂亮?

设置路线的代码如下; 请在我需要处理错误的代码中查看我的注释.

MySchema.find({}, function (err, stubs) {
    if (err) {
        console.log('error while loading');
        return;
    }

    for (var i = 0; i < stubs.length; i++) {
        var bodyMessage = stubs[i].body;

        // This is where we can fail, if only I could make a 
        // check for the route here
        server.route({
            method:  stubs[i].method,
            path: stubs[i].path,

            handler: function (request, reply) {
                reply(bodyMessage);
            }
        });
    }

});
Run Code Online (Sandbox Code Playgroud)

mongodb node.js hapijs

11
推荐指数
2
解决办法
4606
查看次数

Hapi.js与Socket.io - socket.io.js在哪里?

我正在尝试将socket.io挂钩到Hapi.js服务器.我已经测试了vanilla Node.js中的socket.io实现,一切都很好; Hapi实现的服务器端似乎工作正常,但"/socket.io/socket.io.js"资源不会提供给客户端.

我已经检查了Hapi示例,但是他们只显示了在服务器上做了什么,他们在客户端握手上的文档看起来很奇怪:他们在端口8000上有一个服务器,但是说要发布socket.io握手到8080--我甚至试过这个(看起来很不稳定,并且与其他所有socket.io实现不一致)没有运气.

谢谢!

node.js socket.io hapijs

10
推荐指数
1
解决办法
5022
查看次数

异常信息:System.Reflection.TargetInvocationException

我正在研究WPF应用程序,我只在运行时在单个设备上收到此错误.

Exception Info: System.Reflection.TargetInvocationException
Run Code Online (Sandbox Code Playgroud)

我的问题:

  • 任何可能导致此错误的线索?
  • 知道如何在发布模式下调试应用程序吗?

Exception Info: System.Reflection.TargetInvocationException
Stack:
   at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
   at System.Delegate.DynamicInvokeImpl(System.Object[])
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf system.reflection

10
推荐指数
2
解决办法
2万
查看次数

Git在合并时忽略已删除的文件

我有两个存储库.不时,我要的内容合并othermain.但是,合并会忽略已删除的文件.让我通过一个例子解释一下:

mkdir -p test/main test/other

cd test/other/
git init
touch one two three
git add .
git commit -m "Add one, two and three."

cd ../main/
git init
touch four
git add .
git commit -m "Add four."
Run Code Online (Sandbox Code Playgroud)

添加othermain远程.

git remote add other ../other/
git fetch other
Run Code Online (Sandbox Code Playgroud)

合并其内容.

git merge --squash other/master
git commit -m "Merge other."
Run Code Online (Sandbox Code Playgroud)

它正确添加文件.现在,删除一个文件other.

cd ../other/
git rm two
git commit -m "Remove two."
Run Code Online (Sandbox Code Playgroud)

合并更改为main …

git

9
推荐指数
1
解决办法
3052
查看次数

Node.js多行输入

我想提示用户输入,让用户输入多行文本,在每行之间输入,然后按CTRL + D或其他类似的东西终止输入.

使用"按键",我可以捕获EOF,但我必须手动处理所有回声,退格处理,终端转义序列等.如果我可以使用"readline",但以某种方式用"按键"拦截CTRL + D(EOF)会好得多,但我不确定我会怎么做.

keypress readline command-line-interface eof node.js

9
推荐指数
1
解决办法
3152
查看次数

使用嵌套对象进行Hapi/Joi验证

我在其中一条路线上进行了以下验证:

payload: {
    keywordGroups: Joi.array().items(Joi.object().keys({
        language: Joi.string().required(),
        containsAny: Joi.array().items(Joi.string()).default([]).when('containsAll', { is: [], then: Joi.required() }),
        containsAll: Joi.array().items(Joi.string()).default([]).when('containsAny', { is: [], then: Joi.required() }),
        notContainsAll: Joi.array().items(Joi.string()).default([]),
        notContainsAny: Joi.array().items(Joi.string()).default([])
    })).required(),
}
Run Code Online (Sandbox Code Playgroud)

我试图让它containsAnycontainsAll必须至少包含一个字符串.如果containsAny为空,containsAll则应至少有一个项目.如果containsAll是空的,containsAny至少应该包括一个项目.

但是Joi.when当涉及一系列对象时,它似乎并不真正起作用.

javascript validation hapijs joi

9
推荐指数
1
解决办法
5949
查看次数

hapi在发送响应之前设置标头

在hapi处理程序中,我尝试在发送回视图之前在代码中设置我的响应的标头.

reply().header('cache-control', 'no-cache');

{....}

reply.view('myView', myContext);
Run Code Online (Sandbox Code Playgroud)

你我必须使用这种hold方法吗?在这种情况下,如何在渲染视图时重用响应?

谢谢你的帮助.

javascript header handler node.js hapijs

8
推荐指数
4
解决办法
2万
查看次数

位置搜索结果叠加

我正在尝试将一个搜索栏添加到我的某个应用程序中,该应用程序允许用户输入地址信息,并显示带有可能结果的桌面视图(和键盘).基本上与地图应用中提供的功能相同.是否有捷径可寻?

在此输入图像描述

拥有当前位置默认和自动完成功能会很不错,但不是必需的.我可以从头开始构建UI,但我不知道如何取回搜索结果.我可以使用地理编码器并将结果解析为tableview吗?

search location ios

7
推荐指数
1
解决办法
4015
查看次数

在Joi中允许可选参数而不指定它们

我很擅长使用Joi来验证hapi中的请求有效负载.我的问题如下.我有这个定义的路线:

{
    method: 'POST',
    path: '/foo/bar',
    config: {
      description: 'foo.bar',
      handler: handlers.foo,
      auth:false,
      tags: ['api'],
      validate: {
        payload: {
          email : Joi.string().required(),
          password : Joi.string().required(),
        }
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

电子邮件和密码是我要求的属性.但是,我想允许其他属性而不必全部指定它们.例如:

{
  email: foo@bar.com,
  password: fooPass,
  name: myName,
  surname: mySurname
}
Run Code Online (Sandbox Code Playgroud)

Joi有办法做到吗?

javascript node.js hapijs joi

7
推荐指数
2
解决办法
4229
查看次数

如何在Xcode 5旁边安装Xcode 6?

我想知道是否有一种方法可以在Xcode 5旁边安装Xcode 6.我看到有人说你可以,但他们没有真正解释原因.有人可以帮忙解释原因吗?另外,如果我希望将来如何卸载它?

beta xcode install versions

6
推荐指数
1
解决办法
7717
查看次数