How to use umi-mock - 2 common examples

To help you get started, we’ve selected a few umi-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github umijs / umi / packages / umi-serve / bin / umi-serve.js View on Github external
// Gzip support
app.use(
  compression({
    filter: (req, res) => {
      if (req.headers['x-no-compression']) {
        // don't compress responses with this request header
        return false;
      }
      // fallback to standard filter function
      return compression.filter(req, res);
    },
  }),
);

app.use(
  require('umi-mock').createMiddleware({
    cwd,
    config,
    absPagesPath: paths.absPagesPath,
    absSrcPath: paths.absSrcPath,
    watch: false,
    onStart({ paths }) {
      registerBabel(paths);
    },
    onError(e) {
      console.log(e.message);
    },
  }).middleware,
);
app.use(require('serve-static')('dist'));
app.listen(port, () => {
  const ip = getNetworkAddress();
github umijs / umi / packages / umi-build-dev / src / plugins / mock.js View on Github external
if (process.env.MOCK !== 'none' && process.env.HTTP_MOCK !== 'none') {
      const beforeMiddlewares = api.applyPlugins('addMiddlewareBeforeMock', {
        initialValue: [],
      });
      const afterMiddlewares = api.applyPlugins('addMiddlewareAfterMock', {
        initialValue: [],
      });

      beforeMiddlewares.forEach(m => app.use(m));
      const {
        cwd,
        config,
        paths: { absPagesPath, absSrcPath },
      } = api;
      app.use(
        createMiddleware({
          cwd,
          config,
          errors,
          absPagesPath,
          absSrcPath,
          watch: !process.env.WATCH_FILES,
          onStart({ paths }) {
            api.addBabelRegister(paths);
          },
        }).middleware,
      );
      afterMiddlewares.forEach(m => app.use(m));
    }
  });

umi-mock

MIT
Latest version published 2 years ago

Package Health Score

66 / 100
Full package analysis

Popular umi-mock functions

Similar packages