【问题标题】:Lab & getConfig integration实验室和 getConfig 集成
【发布时间】:2015-03-24 03:24:13
【问题描述】:

我正在尝试将 Lab 与 getConfig 一起使用,但总是出错。

在实验室中我需要服务器,但在搜索配置文件时,它会查看 node_modules/lab/bin/test_config.json 而不是在根文件夹中查找 test_config。

有没有办法使用 getConfig 将配置文件传递给实验室?

这是我正在做的事情的简介:

//In the testFile.js
var Lab = require("lab");
var server = require("../index");
(...)

//In index.js
(...)
var config = require('getconfig');
(...)
var server = new Hapi.Server();
server.connection({
  host: config.http.listen,
  port: config.http.port
});
(...)

这是错误抛出:

/index.js:12
host: Cannot read property 'listen' of undefined

【问题讨论】:

    标签: node.js server config hapijs lab


    【解决方案1】:

    您可以使用GETCONFIG_ROOT 环境变量。来自documentation

    在某些情况下,当您的应用未直接运行(例如测试运行程序)时,getconfig 可能无法正确查找您的配置文件。在这种情况下,您可以将GETCONFIG_ROOT 环境变量设置为保存配置的目录。

    所以像这样运行你的测试:

    GETCONFIG_ROOT="/path/to/root" make test
    

    【讨论】:

      猜你喜欢
      • 2018-10-31
      • 1970-01-01
      • 1970-01-01
      • 2022-12-04
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多