Installations
npm install hot-mock-middleware
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=6
Node Version
9.10.1
NPM Version
6.4.1
Score
60.8
Supply Chain
84.2
Quality
66.2
Maintenance
50
Vulnerability
98.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
vanni-li
Download Statistics
Total Downloads
1,389
Last Day
5
Last Week
11
Last Month
29
Last Year
160
GitHub Statistics
3 Stars
17 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
1.27 MB
Minified
476.40 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.9
Package Id
hot-mock-middleware@1.1.9
Unpacked Size
11.09 kB
Size
4.26 kB
File Count
7
NPM Version
6.4.1
Node Version
9.10.1
Total Downloads
Cumulative downloads
Total Downloads
1,389
Last day
0%
5
Compared to previous day
Last week
266.7%
11
Compared to previous week
Last month
480%
29
Compared to previous month
Last year
0%
160
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
6
hot-mock-middleware
A express middleware that creates mock server. Your can specify a directory, the files under the directory are mock files that export interface definitions,support for real-time refresh based on 'require' dynamic analysis.
Installation
1$ npm install --save-dev hot-mock-middleware
Quick start
- Create a directory
mock-server
, then create the fileapp.js
, the content is:
1const express = require('express'); 2const path = require('path'); 3const mockMiddleware = require('hot-mock-middleware'); 4 5const app = express(); 6// Use middleware to create mock server 7app.use( 8 mockMiddleware(path.resolve(__dirname, 'mock')) 9); 10 11app.listen(3000, () => console.log('Example app listening on port 3000!'));
- Create a
mock
directory undermock-server
and createusers.js
as follows:
1// mock/users.js 2 3module.exports = { 4 // supported values are Object and Array 5 'GET /api/users': { users: [1, 2] }, 6 7 // GET can be omitted 8 '/api/users/1': { id: 1 }, 9 10 // support for custom functions, APIs refer to express@4 11 'POST /api/users/create': (req, res) => { res.end('OK'); }, 12};
- Install dependent modules and start app:
1$ npm i -S express hot-mock-middleware 2$ node app.js
The you can then access the http://localhost:3000/api/users to view API documents.
You can create more js files in the mock
directory, the mock server will automatically grab contents, also you can modify these files, ths api data will refresh real-time without restarting app.
Using with Webpack
To use with webpack projects, simply add a setup options to your webpack-dev-server options.
Change your config file webpack.config.js
:
1const path = require('path'); 2const mockMiddleware = require('hot-mock-middleware'); 3 4module.exports = { 5 // ... 6 7 devServer: { 8 before(app) { 9 app.use( 10 mockMiddleware(path.resolve(__dirname, 'mock')) 11 ); 12 } 13 } 14 15 // ... 16}
Let's add a script to easily run the dev server as well: package.json
:
1{ 2 "scripts": { 3 "start": "webpack-dev-server --open", 4 "build": "webpack" 5 } 6}
Then you can add some mock files in mock/
directory.
Using with create-react-app
To use with projects that created with create-react-app, create src/setupProxy.js
as follows:
1// src/setupProxy.js 2const path = require('path'); 3const mockMiddleware = require('hot-mock-middleware'); 4 5module.exports = app => { 6 app.use(mockMiddleware( 7 path.resolve(__dirname, '../mock') 8 )); 9}
Then you can add some mock files in mock/
directory.
Demo
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
2.6
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More