Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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();
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));
}
});