express-ray
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

logo

express-ray

npm version license test status
npm downloads

Install this package in any Express.js project to provide an exceptional debugging experience using the Ray app by Spatie.


Installation

Install this package with npm:

npm install express-ray

Usage

Plugin Installation

To install the express-ray plugin, call the install method provided by the plugin import:

import { plugin as expressRayPlugin } from 'express-ray';

const app = express();

expressRayPlugin.install(app);

Once installed, access ray via the app.$ray() method. See the documentation for the node-ray package for a list of available methods.

app.get('/', (req, res) => {
    app.$ray('sending "hello world" response');
    res.send('hello world');
});

Methods

The app.$ray() method provides additional helper methods specifically for express applications.

Method Description
$ray().request(req) Sends information about the request object to Ray
app.get('/api/test', (req, res) => {
    app.$ray().request(req);
    res.send({ message: 'hello world' });
});

Middleware

SendRequestToRay

Send details about each request to Ray with the SendRequestToRay middleware, optionally specifying configuration settings.

interface SendRequestToRayOptions {
    methods?: HttpMethod[];
    paths?: {
        include?: string[];
        ignore?: string[];
    };
}

By default, all paths and http methods match and get sent to Ray. The paths.include, paths.ignore, and methods configuration settings support wildcards.

import { middleware } from 'express-ray';

app.use(
    middleware.SendRequestToRay({ 
        methods: [HttpMethod.GET],
        paths: { include: ['/api/*'], ignore: ['/api/ignored'] } 
    })
);

All configuration settings for this middleware are optional:

app.use(middleware.SendRequestToRay());

image

SendErrorToRay

To send errors directly to Ray, use the SendErrorToRay middleware.

import { middleware } from 'express-ray';

// <express setup code here>

// register the middleware just before listen()
app.use(middleware.SendErrorToRay);

app.listen(port, () => {
    console.log(`Listening on port ${port}`);
});

Development Setup

npm install
npm run build:dev

Testing

express-ray uses Jest for unit tests. To run the test suite:

npm run test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Readme

Keywords

none

Package Sidebar

Install

npm i express-ray

Weekly Downloads

24

Version

1.2.0

License

MIT

Unpacked Size

15.1 kB

Total Files

7

Last publish

Collaborators

  • patinthehat