{"id":15706115,"url":"https://github.com/kyleross/test-server","last_synced_at":"2025-03-30T15:46:18.026Z","repository":{"id":57126028,"uuid":"173788245","full_name":"KyleRoss/test-server","owner":"KyleRoss","description":"A simple Koa server to respond to any URL and provide the results","archived":false,"fork":false,"pushed_at":"2019-03-04T21:06:07.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T00:43:21.433Z","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/KyleRoss.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":"2019-03-04T17:14:42.000Z","updated_at":"2019-03-04T21:06:09.000Z","dependencies_parsed_at":"2022-08-31T08:20:29.871Z","dependency_job_id":null,"html_url":"https://github.com/KyleRoss/test-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Ftest-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Ftest-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Ftest-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KyleRoss%2Ftest-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KyleRoss","download_url":"https://codeload.github.com/KyleRoss/test-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246342824,"owners_count":20761939,"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-10-03T20:21:34.283Z","updated_at":"2025-03-30T15:46:18.011Z","avatar_url":"https://github.com/KyleRoss.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test Server\nA simple Koa server to respond to any URL and provide the results. Useful for debugging or testing webhook-style responses locally. This is a development server which is not made to run in production.\n\n## Install\nThe package comes with a command line interface as well as a programmatic interface.\n\n### CLI\n```\nnpm install -g @kylerross/test-server\n```\n\n### API\n```\nnpm install --save @kylerross/test-server\n``` \n\n## CLI Usage\nTo start the server, run the following command:\n```\ntest-server\n```\n\n#### Options\n```\n-p NUM, --port=NUM\n    Port number to bind the server to.\n\n--disable-log\n    Disables logging request information to the console.\n\n--disable-body\n    Disables responding to requests with data in the response body.\n\n-b TEXT, --custom-body=TEXT\n    When the body is enabled, override the default sent JSON with the provided text.\n\n--body-fields=LIST\n    Comma-seperated list of fields to include in the response body.\n    Defaults to: url, method, body, query, headers, response, app\n\n--log-fields=LIST\n    Comma-seperated list of fields to include in the log message in the console.\n    Defaults to: body, query, headers\n\n--no-colors\n    Disables colors in the console-logged message.\n\n-v, --version\n    Display the CLI version and exit.\n\n-h, --help\n    Display help and exit.\n```\n\n## API Documentation\nTo use the programmatic API:\n\n```js\nconst testServer = require('@kylerross/test-server');\n\n// Start the server with or without options\ntestServer({\n    //... options\n});\n```\n\n### Options\nThe following options are available to be passed into `testServer()`.\n\n| Option        | Type                | Description                                                                      | Default                                                            |\n|---------------|---------------------|----------------------------------------------------------------------------------|--------------------------------------------------------------------|\n| port          | Number              | The port to bind the server to.                                                  | `8000`                                                             |\n| ignorePaths   | Array\u0026lt;Regexp\u0026gt; | Path regexps to ignore requests to.                                              | `[/favicon/i, /robots\\.txt/i]`                                     |\n| enableLogging | Boolean             | Enables logging request data to the console.                                     | `true`                                                             |\n| enableBody    | Boolean             | Enables returning request data in the response as JSON or value of `customBody`. | `true`                                                             |\n| customBody    | String              | Return the provided text as the body instead of the request data JSON.           | `null`                                                             |\n| colors        | Boolean             | Enables colors when logging to the console.                                      | `true`                                                             |\n| bodyFields    | Array\u0026lt;String\u0026gt; | List of fields to display in the response body.                                  | `['url', 'method', 'body', 'query', 'headers', 'response', 'app']` |\n| logFields     | Array\u0026lt;String\u0026gt; | List of fields to display in the log to console.                                 | `['body', 'query', 'headers']`                                     |\n| parserTypes   | Array\u0026lt;String\u0026gt; | List of parser types to allow for bodyparser. Defaults to all.                   | `['json', 'form', 'text']`                                         |\n| jsonLimit     | String              | The size limit for parsing JSON bodies.                                          | `1mb`                                                              |\n| textLimit     | String              | The size limit for parsing Text bodies.                                          | `1mb`                                                              |\n| formLimit     | String              | The size limit for parsing Form bodies.                                          | `56kb`                                                             |\n| strictJSON    | Boolean             | Strict JSON mode accepts arrays and objects only.                                | `true`                                                             |\n\n#### Allowed Fields\nThe following are the available fields that can be passed into `bodyFields` and `logFields`:\n\n- `url` - The incoming url path (ex. ctx.originalUrl)\n- `method` - The request method (ex. ctx.method)\n- `body` - The parsed incoming body from koa-bodyparser (ex. ctx.request.body)\n- `query` - The parsed query string from koa-qs (ex. ctx.query)\n- `headers` - Incoming headers object (ex. ctx.request.headers)\n- `response` - The response object from Node (ex. ctx.response)\n- `app` - The app object from Koa (ex. ctx.app)\n\n---\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyleross%2Ftest-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyleross%2Ftest-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyleross%2Ftest-server/lists"}