A simple mock server built with Node.js and Express.
HTTP request | Description | Notes |
---|---|---|
/error/timeout/ | Simulates a timeout by never sending a response. | |
/error/network/ | Simulates a network error by closing the connection. | |
/error/malformed-json/ | Returns malformed JSON response. | |
/error/error/ | Throws an intentional error for testing purposes. | |
/mirror/ | Returns the request body as a response. | |
/redirect/{url} | Redirects to the specified URL with configurable status. | |
/request/ | Returns detailed information about the incoming request. | |
/shutdown/ | Triggers a shutdown of the server. | |
/status/{status} | Returns a response with the specified http status code. |
Parameter | Type | Description |
---|---|---|
delay | Number | Delays the response by the specified value in milliseconds. |
- The server implements graceful shutdown handling:
- Responds to SIGTERM signals for clean shutdown.
- Provides a 10-second timeout for graceful shutdown.
- Logs shutdown progress and any errors.
-
Clone this repository:
git clone https://github.com/ryo8000/simple-mock-server.git cd simple-mock-server
-
Build and run the application in a Docker container:
docker build -t simple-mock-server . docker run -p 8000:8000 simple-mock-server
-
Clone this repository:
git clone https://github.com/ryo8000/simple-mock-server.git cd simple-mock-server
-
Install dependencies using Yarn:
yarn install
-
Build the application:
yarn build
-
Run the application:
node dist/server.js
Name | Description | Required | Default Value | Notes |
---|---|---|---|---|
ENABLE_SHUTDOWN | Enables the /shutdown endpoint. | No | false | |
HEADERS_TIMEOUT | HTTP headers timeout in milliseconds. | No | 10000 | Must be > KEEP_ALIVE_TIMEOUT |
KEEP_ALIVE_TIMEOUT | HTTP keep-alive timeout in milliseconds. | No | 5000 | |
LOG_LEVEL | Sets the logging level. (debug, info, warn, error) | No | info | |
NODE_ENV | Sets the environment mode. (development, production, test) | No | development | |
ORIGIN | The value of the Access-Control-Allow-Origin response header. | No | * | |
PORT | Port number for this application. | No | 8000 | |
REQUEST_TIMEOUT | Request timeout in milliseconds. | No | 30000 | Must be > HEADERS_TIMEOUT |
For developer-specific instructions, including details on testing and project structure, see the Development Guide.
This project is licensed under the MIT License.