Express
To integrate Exot Inspector into an Express app, you can utilize Exot’s Express module, which offers request tracing and error handling middlewares.
Install
Usage
For more details, visit the express module repository.
WebSocket server
To connect the Inspector App, you’ll need to expose a WebSocket server, to which the app will connect. The express module comes with a built-in server:
In the example above, the app would connect to ws://localhost:3001/_inspector
.
Server configuration
authorize
- An authorization function; throw an error for unauthorized access.inspector
- The Inspector instance.path
- The WebSocket URL path to which the app can connect.ws
- WebSocket server options, see ws docs.
You can use a custom HTTP server by passing { ws: { noServer: true, server } }
. The request upgrade is handled automatically, and the authorize
function works both ways. It is recommended to use noServer
with authorize
as authorization occurs before the request upgrade.
Security
Recommended steps to secure the WebSocket server:
- Use a unique path with an unguessable token, e.g.,
/_inspector/K7hA9m16...
. This makes it difficult for attackers to guess the path the server is listening on. - Utilize the
authorize
function to check the IP address, a cookie, or an access token. Note that WebSockets don’t support “basic auth”; you’ll need to send the user/password or a token in the query string.
How to
Authorization
To secure the WebSocket server, implement the authorize
function and validate the client’s IP address, a cookie, or an access token:
Tracing
The middleware
automatically traces all requests, and you can easily trace function calls within request handlers using the trace
method from the traces
instrument:
The example above will produce a trace:
The trace
function utilizes Node’s AsyncLocalStorage to automatically detect the context in which the function is executed, eliminating the need to pass any context or parent trace for correct trace nesting.