A simple mock api server
npm install @aquestsrl/mock-api```
npm i @aquestsrl/mock-api`
or`
yarn add @aquestsrl/mock-api
Create mock-api.config.js on your project root:
`
const path= = require('path');
module.exports = () => ({
address: 4002,
publicPath: 'path-to-public-folder',
routes: [
{
route: '/api/hp',
module: path.resolve(__dirname, 'mock/routes/foo'),
},
],
});
`
module.exports = ({
shuffleArray,
shuffleIndexArray,
humanize,
}) => (req, res) => res.json({
foo: 'bar',
image: '/logo.png',
});
`
Usage from CLI
`
mock-api
`Usage as middleware
`
const Express = require('express');
const mock = require('@aquestsrl/mock-api');const App = new Express();
App
.use(mock())
.listen(3000);
`Bundle with Webpack
If you need to bundle data with Webpack, after create the middleware add MockApiPlugin to your webpck configuration: this plugin create an Express application based on your mock-api.config.js, ready to be bundled. If provided, contents of public folder are copied to toPublicPath destination.
`
const path = require('path');
const MockApiPlugin = require('@aquestsrl/mock-api/webpack/plugin');const config = {
...,
plugins: [
new MockApiPlugin({
configPath: path.resolve(__dirname, 'mock-api.config.js'),
toPublicPath: '/public/api', // relative to dist folder
}),
],
};
``