1.2.0 • Published 3 years ago

prerender-cli-mock v1.2.0

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

prerender-cli-mock

A prerender-cli plugin help you to create mock server. It rely on express-mock-api-middleware

Usage

// /mock/userInfo.js
module.exports = {
  'GET /api/user/info': {
    id: 101,
    userName: 'bob',
    email: 'bob@gmail.com',
    firstName: 'Bob',
    lastName: 'Bushee',
  },

  'POST /api/user/login': (req, res) => {
    const { userName, password } = req.body;
    if (userName === 'bob' && password === 'password') {
      res.send({
        success: true,
      });
    } else {
      res.send({
        success: false,
      });
    }
  },

  'GET /api/product/:id': (req, res) => {
    const { id } = req.params;
    res.sendFile(path.join(__dirname, `products/${id}.json`));
  }
};
// prerender.config.js
const PrerenderCliMock = require('prerender-cli-mock');
const path = require('path');
module.exports = {
  plugins: [
    new PrerenderCliMock({
      path: path.resolve(__dirname, './mock'),
    }),
  ]
};
1.2.0

3 years ago

1.1.0

3 years ago

1.1.0-alpha.0

3 years ago

1.0.1-alpha.0

3 years ago