{"id":13464845,"url":"https://github.com/hapipal/hpal-debug","last_synced_at":"2025-09-07T19:32:50.766Z","repository":{"id":56122279,"uuid":"132823721","full_name":"hapipal/hpal-debug","owner":"hapipal","description":"hapijs debugging tools for the hpal CLI","archived":false,"fork":false,"pushed_at":"2022-11-28T04:19:19.000Z","size":78,"stargazers_count":28,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-12-22T02:36:20.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hapipal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-09T23:36:20.000Z","updated_at":"2022-11-28T04:17:57.000Z","dependencies_parsed_at":"2023-01-23T21:00:54.186Z","dependency_job_id":null,"html_url":"https://github.com/hapipal/hpal-debug","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Fhpal-debug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Fhpal-debug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Fhpal-debug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hapipal%2Fhpal-debug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hapipal","download_url":"https://codeload.github.com/hapipal/hpal-debug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232140248,"owners_count":18478224,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T14:00:51.469Z","updated_at":"2025-01-02T20:26:56.356Z","avatar_url":"https://github.com/hapipal.png","language":"JavaScript","readme":"# hpal-debug\n\nhapijs debugging tools for the [hpal CLI](https://github.com/hapipal/hpal)\n\n[![Build Status](https://travis-ci.com/hapipal/hpal-debug.svg?branch=main)](https://travis-ci.com/hapipal/hpal-debug) [![Coverage Status](https://coveralls.io/repos/hapipal/hpal-debug/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/hapipal/hpal-debug?branch=main)\n\nLead Maintainer - [Devin Ivy](https://github.com/devinivy)\n\n`hpal-debug` was designed to help you,\n  - :ant: display information about your routes in a neat, customizable table.\n    \u003e `hpal run debug:routes --show cors`\n  - :beetle: use your hapi server, [models](https://github.com/hapipal/schwifty), [services](https://github.com/hapipal/schmervice), etc. interactively through a REPL.\n    \u003e `hpal run debug:repl`\n  - :bug: hit your routes from the command line without having to restart your server.\n    \u003e `hpal run debug:curl post /user --name Pal -v`\n\n## Installation\n\u003e If you're getting started with [the pal boilerplate](https://github.com/hapipal/boilerplate), then your project is already setup with hpal-debug!\n\n1. Install the hpal-debug package from npm as a dev dependency.\n\n   ```sh\n   npm install --save-dev @hapipal/hpal-debug\n   ```\n\n2. Register hpal-debug on your server as a hapi plugin.\n\n   ```js\n   await server.register(require('@hapipal/hpal-debug'));\n   ```\n\n3. Ensure `server.js` or `server/index.js` exports a function named `deployment` that returns your configured hapi server.\n\n   Below is a very simple example of boilerplate code to configure a hapi server server, and is not necessarily \"production-ready.\"  For a more complete setup, consider using [the pal boilerplate](https://github.com/hapipal/boilerplate), or check-out its approach as seen [here](https://github.com/hapipal/boilerplate/blob/pal/server/index.js).\n\n   ```js\n   // server.js\n\n   'use strict';\n\n   const Hapi = require('hapi');\n   const AppPlugin = require('./app');\n\n   // hpal will look for and use exports.deployment()\n   // as defined below to obtain a hapi server\n\n   exports.deployment = async ({ start } = {}) =\u003e {\n\n       const server = Hapi.server();\n\n       // Assuming your application (its routes, etc.) live in a plugin\n       await server.register(AppPlugin);\n\n       if (process.env.NODE_ENV !== 'production') {\n           await server.register(require('@hapipal/hpal-debug'));\n       }\n\n       if (start) {\n           await server.start();\n           console.log(`Server started at ${server.info.uri}`);\n       }\n\n       return server;\n   };\n\n   // Start the server only when this file is\n   // run directly from the CLI, i.e. \"node ./server\"\n\n   if (!module.parent) {\n       exports.deployment({ start: true });\n   }\n   ```\n\nAnd that's it!  Now the hpal-debug commands should be available through the [hpal CLI](https://github.com/hapipal/hpal).  A simple way to check that hpal-debug is setup correctly is to output a pretty display of your route table,\n\n```sh\nnpx hpal run debug:routes\n```\n\n## Usage\n\u003e hpal-debug is intended for use with hapi v19+ and nodejs v12+ (_see v1 for lower support_).\n\n### Commands\n#### `hpal run debug:routes`\n\u003e ```\n\u003e hpal run debug:routes [\u003croute-identifier\u003e] --hide \u003ccolumn-name\u003e --show \u003ccolumn-name\u003e\n\u003e   e.g. hpal run debug:routes --show cors\n\u003e ```\n\nThis command outputs a neat display of your server's route table.\n\nIn order to display a single route, you may specify `\u003croute-identifier\u003e` as a route id (e.g. `user-create`), route method and path (e.g. `post /users`), or route path (e.g. `/users`, method defaulting to `get`).\n\nColumns may be hidden or shown using the `-H` `--hide` and `-s` `--show` flags respectively.  Use the flag multiple times to hide or show multiple columns.  Below is the list of available columns.\n\n`method` `path` `id` `plugin` `vhost` `auth` `cors` `tags` `description`\n\nThe `-r` `--raw` flag will output a minimally formatted table with columns separated by tab characters.  Non-TTY usage automatically defaults to raw output.\n\nA summary of these options can be displayed with the `-h` `--help` flag.\n\n#### `hpal run debug:repl`\n\u003e ```\n\u003e hpal run debug:repl\n\u003e ```\n\nThis command starts a fully-featured interactive REPL with your initialized `server` in context.  Each of your server's methods, properties, [schwifty](https://github.com/hapipal/schwifty) models, and [schmervice](https://github.com/hapipal/schmervice) services are also made directly available for convenience.  Under [hpal](https://github.com/hapipal/hpal) v2 you can use top-level `await`.  You may also call this command using `hpal run debug`.\n\n##### Example\n```js\n$ hpal run debug:repl\n\nhpal\u003e server.info                 // you can always use the server directly\n{ created: 1527567336111,\n  started: 0,\n  host: 'your-computer.local',\n  ...\nhpal\u003e                             // or you can omit the \"server.\" for public properties and methods...\nhpal\u003e\nhpal\u003e info.uri                    // at what URI would I access my server?\n'http://your-computer.local'\nhpal\u003e Object.keys(registrations)  // what plugins are registered?\n[ '@hapipal/hpal-debug', 'my-app' ]\nhpal\u003e table().length              // how many routes are defined?\n12\nhpal\u003e !!match('get', '/my/user')  // does this route exist?\ntrue\nhpal\u003e .exit\n```\n\n#### `hpal run debug:curl`\n\u003e ```\n\u003e hpal run debug:curl \u003croute-identifier\u003e [\u003croute-parameters\u003e] --data \u003craw-payload\u003e --header \u003cheader-info\u003e --raw --verbose\n\u003e   e.g. hpal run debug:curl post /users --firstName Paldo -v\n\u003e ```\n\nThis command makes a request to a route and displays the result.  Notably, you don't need a running server in order to test your route using `hpal run debug:curl`!\n\nIt's required that you determine which route to hit by specifying a `\u003croute-identifier\u003e` as a route id (e.g. `user-create`), route method and path (e.g. `post /users`), or route path (e.g. `/users`, method defaulting to `get`).\n\nYou may specify any payload, query, or path params as `\u003croute-parameters\u003e` flags or in the `\u003croute-identifier\u003e`.  Any parameter that utilizes Joi validation through [`route.options.validate`](https://hapi.dev/api/#route.options.validate) has a command line flag.  For example, a route with id `user-update`, method `patch`, and path `/user/{id}` that validates the `id` path parameter and a `hometown` payload parameter might be hit using the following commands,\n```sh\nhpal run debug:curl patch /user/42 --hometown \"Buenos Aires\"\n\n# or\n\nhpal run debug:curl user-update --id 42 --hometown \"Buenos Aires\"\n```\n\nNested parameters may also be specified.  If the route in the previous example validated payloads of the form `{ user: { hometown } }`, one might use one of the following commands instead,\n```sh\nhpal run debug:curl user-update --id 42 --user-hometown \"Buenos Aires\"\n\n# or\n\nhpal run debug:curl user-update --id 42 --user '{ \"hometown\": \"Buenos Aires\" }'\n```\n\nThe `-d` `--data` flag may be used to specify a request payload as a raw string.\n\nThe `-H` `--header` flag may be used to specify a request header in the format `header-name: header value`.  This flag may be used multiple times to set multiple headers.\n\nThe `-r` `--raw` and `-v` `--verbose` flags affect the command's output, and may be used in tandem with each other or separately.  The `-r` `--raw` flag ensures all output is unformatted, while the `-v` `--verbose` flag shows information about the request and response including timing, the request payload, request headers, response headers, status code, and response payload.  Non-TTY usage automatically defaults to raw output.\n\nA summary of these options can be displayed with the `-h` `--help` flag.\n\n##### Example\n\n```\n$ hpal run debug:curl /user -v\n\nget /user (30ms)\n\nrequest headers\n───────────────────────────────────────────────────────────────────\n user-agent    shot\n host          your-computer.local:0\n\nresponse headers\n───────────────────────────────────────────────────────────────────\n content-type      application/json; charset=utf-8\n vary              origin\n cache-control     no-cache\n content-length    55\n accept-ranges     bytes\n\nresult (200 ok)\n───────────────────────────────────────────────────────────────────\n{\n  id: 42,\n  firstName: 'Paldo',\n  hometown: 'Buenos Aires'\n}\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapipal%2Fhpal-debug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhapipal%2Fhpal-debug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhapipal%2Fhpal-debug/lists"}