Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.use(compression());
app.use(utils.rewritePath);
app.use(
express.static(hopsConfig.buildDir, {
maxAge: '1y',
setHeaders: function(res, filepath) {
if (mime.getType(filepath) === 'text/html' || filepath.match(swRe)) {
helmet.noCache()(null, res, function() {});
}
},
redirect: false,
})
);
utils.bootstrap(app, hopsConfig);
if (options && !options.static) {
var filePath = path.join(hopsConfig.cacheDir, 'server.js');
if (fs.existsSync(filePath)) {
utils.registerMiddleware(app.use(helmet.noCache()), require(filePath));
} else {
console.log(
'No middleware found. Delivering only statically built routes.'
);
}
}
utils.teardown(app, hopsConfig);
return app;
}
module.indexOf('hops') === 0 ||
module.indexOf('core-js') === 0 ||
module.indexOf('babel-polyfill') === 0 ||
!/\.(?:js|json|mjs|node)$/.test(require.resolve(module)) ||
checkEsnext(module)
);
}
var modulesDir = findNodeModules(process.cwd());
module.exports = {
target: 'node',
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
entry: require.resolve('../shims/node'),
output: {
path: hopsConfig.cacheDir,
publicPath: '/',
pathinfo: true,
filename: 'server.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: function(info) {
return path.resolve(info.absoluteResourcePath).replace(/\\/g, '/');
},
},
context: hopsConfig.appDir,
resolve: require('../sections/resolve')('node'),
externals: [
require('webpack-node-externals')({
modulesDir: modulesDir,
whitelist: shouldIncludeExternalModuleInBundle,
}),
],
assetKeys.reduce(function(result, assetKey) {
if (regExp.test(assetKey)) {
var fileName = path.resolve(hopsConfig.cacheDir, assetKey);
var fileContent = compilation.assets[assetKey].source();
delete compilation.assets[assetKey];
result.push(
new Promise(function(resolve, reject) {
mkdirp.sync(hopsConfig.cacheDir);
fs.writeFile(fileName, fileContent, function(err) {
err ? reject(err) : resolve();
});
})
);
}
return result;
}, [])
)
module.exports = function runBuild(options, callback) {
var build = getBuildFunction(options, callback);
if (options.clean) {
var dirs = [hopsConfig.buildDir, hopsConfig.cacheDir];
return cleanup(dirs).then(build);
} else {
return build();
}
};
module.exports = function(options, callback) {
if (options.clean) {
var dirs = [hopsConfig.buildDir, hopsConfig.cacheDir];
return cleanup(dirs).then(runDevelop.bind(null, options, callback));
} else {
return runDevelop(options, callback);
}
};
assets.css.push('/' + assetPath);
}
if (path.extname(assetPath) === '.js') {
if (assetPath.indexOf('vendor-') >= 0) {
assets.js.unshift('/' + assetPath);
} else {
assets.js.push('/' + assetPath);
}
}
return assets;
},
{ css: [], js: [] }
);
var fileName = path.resolve(hopsConfig.cacheDir, 'manifest.json');
var fileContent = JSON.stringify(assets, null, 2);
mkdirp.sync(hopsConfig.cacheDir);
fs.writeFile(fileName, fileContent, callback);
});
};
new Promise(function(resolve, reject) {
mkdirp.sync(hopsConfig.cacheDir);
fs.writeFile(fileName, fileContent, function(err) {
err ? reject(err) : resolve();
});
})
);
}
if (path.extname(assetPath) === '.css') {
assets.css.push('/' + assetPath);
}
if (path.extname(assetPath) === '.js') {
if (assetPath.indexOf('vendor-') >= 0) {
assets.js.unshift('/' + assetPath);
} else {
assets.js.push('/' + assetPath);
}
}
return assets;
},
{ css: [], js: [] }
);
var fileName = path.resolve(hopsConfig.cacheDir, 'manifest.json');
var fileContent = JSON.stringify(assets, null, 2);
mkdirp.sync(hopsConfig.cacheDir);
fs.writeFile(fileName, fileContent, callback);
});
};