Socket
Socket
Sign inDemoInstall

@kylerross/test-server

Package Overview
Dependencies
78
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @kylerross/test-server

A simple Koa server to respond to any URL and provide the results


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Test Server

A 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.

Install

The package comes with a command line interface as well as a programmatic interface.

CLI

npm install -g @kylerross/test-server

API

npm install --save @kylerross/test-server

CLI Usage

To start the server, run the following command:

test-server
Options
-p NUM, --port=NUM
    Port number to bind the server to.

--disable-log
    Disables logging request information to the console.

--disable-body
    Disables responding to requests with data in the response body.

-b TEXT, --custom-body=TEXT
    When the body is enabled, override the default sent JSON with the provided text.

--body-fields=LIST
    Comma-seperated list of fields to include in the response body.
    Defaults to: url, method, body, query, headers, response, app

--log-fields=LIST
    Comma-seperated list of fields to include in the log message in the console.
    Defaults to: body, query, headers

--no-colors
    Disables colors in the console-logged message.

-v, --version
    Display the CLI version and exit.

-h, --help
    Display help and exit.

API Documentation

To use the programmatic API:

const testServer = require('@kylerross/test-server');

// Start the server with or without options
testServer({
    //... options
});

Options

The following options are available to be passed into testServer().

OptionTypeDescriptionDefault
portNumberThe port to bind the server to.8000
ignorePathsArray<Regexp>Path regexps to ignore requests to.[/favicon/i, /robots\.txt/i]
enableLoggingBooleanEnables logging request data to the console.true
enableBodyBooleanEnables returning request data in the response as JSON or value of customBody.true
customBodyStringReturn the provided text as the body instead of the request data JSON.null
colorsBooleanEnables colors when logging to the console.true
bodyFieldsArray<String>List of fields to display in the response body.['url', 'method', 'body', 'query', 'headers', 'response', 'app']
logFieldsArray<String>List of fields to display in the log to console.['body', 'query', 'headers']
parserTypesArray<String>List of parser types to allow for bodyparser. Defaults to all.['json', 'form', 'text']
jsonLimitStringThe size limit for parsing JSON bodies.1mb
textLimitStringThe size limit for parsing Text bodies.1mb
formLimitStringThe size limit for parsing Form bodies.56kb
strictJSONBooleanStrict JSON mode accepts arrays and objects only.true
Allowed Fields

The following are the available fields that can be passed into bodyFields and logFields:

  • url - The incoming url path (ex. ctx.originalUrl)
  • method - The request method (ex. ctx.method)
  • body - The parsed incoming body from koa-bodyparser (ex. ctx.request.body)
  • query - The parsed query string from koa-qs (ex. ctx.query)
  • headers - Incoming headers object (ex. ctx.request.headers)
  • response - The response object from Node (ex. ctx.response)
  • app - The app object from Koa (ex. ctx.app)

License

MIT

FAQs

Last updated on 04 Mar 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc