1.1.2 • Published 5 years ago

@aquestsrl/mock-api v1.1.2

Weekly downloads
3
License
ISC
Repository
-
Last release
5 years ago

@aquestsrl/mock-api

A simple mock api server

Getting started

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'),
    },
  ],
});

Example route module

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
    }),
  ],
};
1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago