http-mock-middleware
A Http Mock Middleware for Express.js
Install
npm install --save http-mock-middleware
Usage
const mockMiddleware = require('http-mock-middleware')
const mockDirectory = 'mock'
app.use(mockMiddleware(mockDirectory))
Mock Data (under /mock)
/api/test.json => /api/test.json.js
module.exports = {
success: true,
msg: 'Hello, Node.js!'
}
module.exports = function(req, res) {
setTimeout(() => {
res.json({
success: true,
msg: 'Hello, Node.js!'
})
}, 2000)
}
module.exports = function(req, res) {
res.json({
success: true,
msg: req.params.test_id
})
}
module.exports = function(req) {
return {
success: true,
msg: req.params.test_id
})
}
module.exports = {
__GET: {
success: true,
msg: 'Hello, Node.js!'
},
__POST: {
success: 'true'
}
}