hpal 调试
happijs 调试工具 hpal CLI (英语)
主维护者 - 变形常春藤
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!
-
从 npm 安装 hpal- debug 包作为 dev 依赖 .
npm install --save-dev @hapipal/hpal-debug -
在您的服务器上注册 hpal-debug 作为 hopi 插件 .
await server.register(require('@hapipal/hpal-debug')); -
保证
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'
}