@hapipal/hpal-debug

中文文档
2.1.0发布于 2022/11/28MITCommonJS近 30 天下载 4634

hpal CLI 调试工具

中文使用文档
文档目录3 节
  1. 安装
  2. 使用量
  3. 图标

hpal 调试

happijs 调试工具 hpal CLI (英语)

Build Status Coverage Status

主维护者 - 变形常春藤

hpal-debug 是为了帮助你,

  • :ant: 在一个整洁,自定义的表格中显示您的路线信息.

    hpal run debug:routes --show cors

  • : beetle: 使用您的 hopi 服务器, 模型, (中文(简体) ), 服务等,通过REPL进行互动.

    hpal run debug:repl

  • : bug: 从命令行切入您的路由而无需重新启动您的服务器 .

    hpal run debug:curl post /user --name Pal -v

安装

如果你开始 朋友锅炉板,那么你的项目已经设置了 hpal -debug!

  1. 从 npm 安装 hpal- debug 包作为 dev 依赖 .

    npm install --save-dev @hapipal/hpal-debug
    
  2. 在您的服务器上注册 hpal-debug 作为 hopi 插件 .

    await server.register(require('@hapipal/hpal-debug'));
    
  3. 保证 server.js 或者说 server/index.js 导出一个名为函数的函数 deployment 返回您配置的 hopi 服务器 .

    下面是一个非常简单的锅炉平板代码的例子,用来配置一个popi服务器服务器,而不一定是"生产准备". 对于更完整的设置,考虑使用 朋友锅炉板,或查看其方法 这里。 。 。 .

    // server.js
    
    'use strict';
    
    const Hapi = require('hapi');
    const AppPlugin = require('./app');
    
    // hpal will look for and use exports.deployment()
    // as defined below to obtain a hapi server
    
    exports.deployment = async ({ start } = {}) => {
    
        const server = Hapi.server();
    
        // Assuming your application (its routes, etc.) live in a plugin
        await server.register(AppPlugin);
    
        if (process.env.NODE_ENV !== 'production') {
            await server.register(require('@hapipal/hpal-debug'));
        }
    
        if (start) {
            await server.start();
            console.log(`Server started at ${server.info.uri}`);
        }
    
        return server;
    };
    
    // Start the server only when this file is
    // run directly from the CLI, i.e. "node ./server"
    
    if (!module.parent) {
        exports.deployment({ start: true });
    }
    

就这样! 现在 hpal-debug 命令应该可以通过 hpal CLI (英语)。一个简单的检查hpal-debug正确设置的方法就是输出一个漂亮的显示您的路由表,

npx hpal run debug:routes

使用量

hpal-debug 用于 hopi v19+ 和 nodejs v12+ ()下级支持参见 v1) (中文(简体) ).

图标

hpal run debug:routes

hpal run debug:routes [<route-identifier>] --hide <column-name> --show <column-name>
  e.g. hpal run debug:routes --show cors

此命令输出您服务器路由表的清晰显示 .

为了显示单一路线, 您可以指定 <route-identifier> 作为路由标识(例如:. user-create),路线方法和路径(例如. post /users),或路由路径(例如. /users方法默认为 get) (中文(简体) ).

可能使用 -H --hide 财务报告和审定财务报表 -s --show 分别为旗帜。 使用多回旗来隐藏或显示多回列. 以下为可用列列表.

method path id plugin vhost auth cors tags description

这个 -r --raw 旗帜将输出一个最小格式的表格,由标签字符分隔出列。 非TTY使用自动默认为原始输出.

这些选项的概要可随 -h --help 旗帜.

hpal run debug:repl

hpal run debug:repl

此命令在您初始化后启动一个全功能的交互式 REPL server 在背景方面。 你的服务器的每一个方法,属性, 轻而易举 模型,以及 缩写 此外,还直接提供方便服务。 下 掌声 v2 您可以使用顶级 await。您也可以使用 hpal run debug。 。 。 .

示例
$ hpal run debug:repl

hpal> server.info                 // you can always use the server directly
{ created: 1527567336111,
  started: 0,
  host: 'your-computer.local',
  ...
hpal>                             // or you can omit the "server." for public properties and methods...
hpal>
hpal> info.uri                    // at what URI would I access my server?
'http://your-computer.local'
hpal> Object.keys(registrations)  // what plugins are registered?
[ '@hapipal/hpal-debug', 'my-app' ]
hpal> table().length              // how many routes are defined?
12
hpal> !!match('get', '/my/user')  // does this route exist?
true
hpal> .exit

hpal run debug:curl

hpal run debug:curl <route-identifier> [<route-parameters>] --data <raw-payload> --header <header-info> --raw --verbose
  e.g. hpal run debug:curl post /users --firstName Paldo -v

此命令向一个路由提出请求并显示结果 。 值得注意的是,您不需要运行中的服务器来测试您的路径 hpal run debug:curl来啊!

需要您通过指定一个 <route-identifier> 作为路由标识(例如:. user-create),路线方法和路径(例如. post /users),或路由路径(例如. /users方法默认为 get) (中文(简体) ).

您可以指定任何有效载荷、查询或路径参数为 <route-parameters> 旗帜或 <route-identifier>通过 JOI 验证使用的任何参数 route.options.validate 拥有命令行旗。 例如,带有 id 的路由 user-update方法 patch路径 /user/{id} 验证 id 路径参数和 a hometown 使用下列命令可以击中有效载荷参数,

hpal run debug:curl patch /user/42 --hometown "Buenos Aires"

# or

hpal run debug:curl user-update --id 42 --hometown "Buenos Aires"

也可以指定被嵌入的参数。 如果前一示例中的路径验证了该形式的有效载荷 { user: { hometown } },人们可能会使用以下命令之一,

hpal run debug:curl user-update --id 42 --user-hometown "Buenos Aires"

# or

hpal run debug:curl user-update --id 42 --user '{ "hometown": "Buenos Aires" }'

这个 -d --data 可使用旗帜指定请求的有效载荷为生字符串.

这个 -H --header 标记可以用于在格式中指定请求头 header-name: header value。此旗帜可能多次用于设置多条标题.

这个 -r --raw 财务报告和审定财务报表 -v --verbose 旗帜会影响命令的输出,并且可以互相并用或单独使用. 这个 -r --raw 旗帜确保所有输出未格式化,而 -v --verbose 旗帜显示有关请求和响应的信息,包括时间、请求的有效载荷、请求头、响应头、状态代码和响应有效载荷。 非TTY使用自动默认为原始输出.

这些选项的概要可随 -h --help 旗帜.

示例
$ hpal run debug:curl /user -v

get /user (30ms)

request headers
───────────────────────────────────────────────────────────────────
 user-agent    shot
 host          your-computer.local:0

response headers
───────────────────────────────────────────────────────────────────
 content-type      application/json; charset=utf-8
 vary              origin
 cache-control     no-cache
 content-length    55
 accept-ranges     bytes

result (200 ok)
───────────────────────────────────────────────────────────────────
{
  id: 42,
  firstName: 'Paldo',
  hometown: 'Buenos Aires'
}

版本与发布记录

@hapipal/hpal-debug 共发布 2 个版本,首次发布于 2021/01/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.1.0latest2022/11/283 年前
2.0.02021/01/065 年前

关于 @hapipal/hpal-debug 的常见问题

@hapipal/hpal-debug 是什么?

hpal CLI 调试工具

如何安装 @hapipal/hpal-debug?

在项目目录运行 npm install @hapipal/hpal-debug,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@hapi/hapi(>=19 <22)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@hapipal/hpal-debug 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/hapipal__hpal-debug 是否存在。

@hapipal/hpal-debug 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@hapipal/hpal-debug 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@hapipal/hpal-debug 可以商用吗?

@hapipal/hpal-debug 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@hapipal/hpal-debug 的下载量有多少?

根据 npm 官方下载统计,@hapipal/hpal-debug 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,634 次,日均约 154 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@hapipal/hpal-debug 还在维护吗?

最新版本 2.1.0 发布于 2022/11/28(3 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/01/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。