Skip to main content Link Search Menu Expand Document (external link)

The Web Interface

The Web Interface exposes a local HTTP server embeded in Jancy that clients can make requests against.

There is only one web interface and it can always be found at jancy.webInterface.

Methods

webInterface.addCustomEndpoint(path, handler)

  • path (string)
  • handler (function)

Adds a custom endpoint to the web interface. The actual path exposed by the web interface will be /extra/<path>. When a request is received on the custom endpoint handler will be called with the following arguments:

The return value of the handler function will be passed to JSON.stringify and the result of that will be returned to the client. If the handler returns null it’s assumed the handler will handle res and propertly end it.

function myHandler(jancy, parsedURL, req, res) {
  jancy.console.log('my-custom-endpoint was called');
  return true;
}
jancy.webInterface.addCustomEndpoint('/my-custom-endpoint', myHandler);

webInterface.removeCustomEndpoint(path)

Removes a custom endpoint from the web interface that was previously added with webInterface.addCustomEndpoint().

jancy.webInterface.removeCustomEndpoint('/my-custom-endpoint');