This project provides a local Node.js server built with Express that can be installed and run using the @wesflo/mock-server
package. The server is designed to respond to requests from a Chrome extension and return a mock JSON response.
You can install the server via npm:
npm i @wesflo/mock-server
Alternatively, for easier usage, you can install the package globally:
npm install -g @wesflo/mock-server
To start the server, use npx
:
npx wf-serve
Alternatively, if you installed the package globally, you can start the server directly:
wf-serve
Once the server is running, it listens for requests from your Chrome extension. The extension will send a request to the server, which then processes it and responds with a mock JSON based on the parameters.
The server expects the following query parameters:
status
– HTTP status code to return (e.g., 200, 404)to
– Timeout duration in millisecondspath
– The path to the mock JSON filepDir
– The directory path where the mock file is locatedA request from your Chrome extension might look like:
fetch('http://localhost:3000/mock?status=200&to=1000&path=mockData.json&pDir=mock')
.then(response => response.json())
.then(data => console.log(data));