Gathering detailed insights and metrics for vite-plugin-mockit
Gathering detailed insights and metrics for vite-plugin-mockit
Gathering detailed insights and metrics for vite-plugin-mockit
Gathering detailed insights and metrics for vite-plugin-mockit
npm install vite-plugin-mockit
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
5 Stars
15 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Aug 16, 2022
Latest Version
1.0.2
Package Id
vite-plugin-mockit@1.0.2
Unpacked Size
35.80 kB
Size
8.94 kB
File Count
25
NPM Version
6.14.6
Node Version
12.18.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
local mock data functionality for vite, support vite 1.x and vite 2.x
1yarn add vite-plugin-mockit
https://github.com/xuxihai123/vite-mock-example
1module.exports = { 2 'GET /api/user': { username: 'admin', sex: 5 }, 3 'GET /api/list': function (req, res) { 4 let query = req.query || {}; 5 return res.json({ 6 limit: query.limit, 7 offset: query.offset, 8 list: [ 9 { username: 'admin1', sex: 1 }, 10 { username: 'admin2', sex: 0 }, 11 ], 12 }); 13 }, 14 'GET /repos/hello': (req, res) => { 15 return res.json({ 16 text: 'this is from mock server', 17 }); 18 }, 19 'GET /api/userinfo/:id': (req, res) => { 20 return res.json({ 21 id: req.params.id, 22 username: 'kenny', 23 }); 24 }, 25 'GET /api/user/list/:id/:type': (req, res) => { 26 return res.json({ 27 id: req.params.id, 28 type: req.params.type, 29 }); 30 }, 31 32 'POST /api/login/account': (req, res) => { 33 const { password, username } = req.body; 34 if (password === '888888' && username === 'admin') { 35 return res.json({ 36 status: 'ok', 37 code: 0, 38 token: 'sdfsdfsdfdsf', 39 data: { 40 id: 1, 41 username: 'kenny', 42 sex: 6, 43 }, 44 }); 45 } else { 46 return res.json({ status: 'error', code: 403 }); 47 } 48 }, 49 'DELETE /api/user/:id': (req, res) => { 50 res.send({ status: 'ok', message: '删除成功!' }); 51 }, 52};
1module.exports = [ 2 { 3 path: '/api/user', 4 handler: (req, res) => { 5 return res.json({ username: 'admin', sex: 5 }); 6 }, 7 }, 8 { 9 path: '/api/list', 10 handler: function (req, res) { 11 let query = req.query || {}; 12 return res.json({ 13 limit: query.limit, 14 offset: query.offset, 15 list: [ 16 { username: 'admin1', sex: 1 }, 17 { username: 'admin2', sex: 0 }, 18 ], 19 }); 20 }, 21 }, 22 { 23 path: '/repos/hello', 24 handler: (req, res) => { 25 return res.json({ text: 'this is from mock server' }); 26 }, 27 }, 28 { 29 path: '/api/userinfo/:id', 30 handler: (req, res) => { 31 return res.json({ 32 id: req.params.id, 33 username: 'kenny', 34 }); 35 }, 36 }, 37 { 38 path: '/api/user/list/:id/:type', 39 handler: (req, res) => { 40 return res.json({ 41 id: req.params.id, 42 type: req.params.type, 43 }); 44 }, 45 }, 46 { 47 path: '/api/login/account', 48 method: 'post', 49 handler: (req, res) => { 50 const { password, username } = req.body; 51 if (password === '888888' && username === 'admin') { 52 return res.json({ 53 status: 'ok', 54 code: 0, 55 token: 'sdfsdfsdfdsf', 56 data: { 57 id: 1, 58 username: 'kenny', 59 sex: 6, 60 }, 61 }); 62 } else { 63 return res.json({ status: 'error', code: 403 }); 64 } 65 }, 66 }, 67 { 68 method: 'delete', 69 path: '/api/user/:id', 70 handler: (req, res) => { 71 res.send({ status: 'ok', message: '删除成功!' }); 72 }, 73 }, 74];
1const mockPlugin = require("vite-plugin-mockit"); 2 3module.exports = { 4 plugins: [ 5 mockPlugin({ 6 entry: "./mock/index.js", 7 watchFiles: [], // watch file or dir change refresh mock 8 watchOptions: {}, //extension option from chokidar option 9 ignore: /_test/ // ignore change, support function or regex 10 // debug: true, // debug log 11 disable: false // default false 12 }) 13 ] 14}; 15
1➜ ~ curl -X GET http://127.0.0.1:4000/api/user 2{"id":1,"username":"kenny","sex":6} 3➜ ~ curl -X GET http://127.0.0.1:4000/api/user/list 4[{"id":1,"username":"kenny","sex":6},{"id":2,"username":"kenny","sex":6}] 5➜ ~ curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"username":"admin","password":"888888"}' http://127.0.0.1:4000/api/login/account 6{"status":"ok","code":0,"token":"sdfsdfsdfdsf","data":{"id":1,"username":"kenny","sex":6}} 7➜ ~ curl -X DELETE http://127.0.0.1:4000/api/user/88 8{"status":"ok","message":"delete success!"}
mock config entry,The default value is./mock/index.js.
watch file or dir change refresh mock, include default entry and entry file directory
extension option from chokidar option
ignore file change, support function or regex, It is used to prevent refresh
Whether to turn on local debugging information,The default value is false
The plugin will only work in a development environment , if you want to disable it, set disable to true, The default value is false
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/15 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
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
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