Important
There are two ways to use REserve :
- Run as a standalone command line with a configuration file (default name is
reserve.json
)
{
"port": 8080,
"mappings": [{
"match": "^/private/",
"status": 403
}, {
"match": "^/(.*)",
"file": "./$1"
}, {
"status": 404
}]
}
Example of
reserve.json
configuration file
Note
If process.send
is available, REserve notifies the parent process when the server is ready by sending the message 'ready'
.
- Embed with its configuration in a custom application
import { serve, log } from 'reserve'
log(serve({
"port": 8080,
"mappings": [{
"match": "^/private/",
"status": 403
}, {
"match": "^/(.*)",
"file": "./$1"
}, {
"status": 404
}]
}))
Example of reserve being embedded in an application
In both cases, the configuration must comply with the properties and mappings documented here.
REserve is delivered with the following default handlers :
file
: to serve resources from the file systemstatus
: to end response with a specific statusurl
: to serve resources from a web addresscustom
: to enable custom codinguse
: to integrate packaged middlewares (express)
Other additional handlers can be installed separately and plugged through the handlers
configuration property.
If you plan to build your own handler, here is what you need to know.
The REserve server object implements an interface that mimics the EventEmitter::on method and, during execution, it triggers events with parameters to notify any listener of its activity.
REserve exports methods and helpers to simplify implementations :
serve
: to start the serverread
: to read a configuration file, supportsextends
check
: to check a configurationlog
: to handle and output server logsinterpolate
: to interpolate values in a string or an objectbody
: to read a request bodysend
: to build a responsecapture
: to copy the response stream to another stream (for instance: to create a cache)punycache
: a minimalist cache implementation
REserve includes a mocking environment to ease the tests. It takes the configuration and returns a fake server object augmented with a request
method to simulate incoming requests.
Here is the history of versions with their associated changes.
Sometimes, a simple idea leads to very interesting projects. This article explains the creation of REserve best described as a lightweight web server statically configurable with regular expressions that can also be embedded and extended.
Based on a clean concept, the development of REserve follows a simple architecture that enables flexibility and extensibility. This article provides keys to understand the modular structure of the implementation.
The best way to explain what REserve can do is to demonstrate some of its features through a concrete use case. This article illustrates how one can quickly setup a server to facilitate the execution of OpenUI5 applications.
With version 1.8.0, REserve offers the capture helper that enables the copy of the response content while processing a request. In this article, an example will be presented in two different flavors to illustrate the new possibilities introduced by this tool.
A benchmark realized to compare performances of express, koa, fastify and REserve.