Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function(webpackConfig) {
var render = createRenderer(webpackConfig);
return Promise.all(
(hopsConfig.locations || []).map(function(location) {
return render(location).then(function(html) {
if (html) {
return writeFile(location, html);
}
});
})
).then(function() {
console.log(/* empty line */);
});
};
'use strict';
process.env.NODE_ENV = 'production';
const serverlessHttp = require('serverless-http');
const config = require('hops-config');
const { trimSlashes } = require('pathifist');
const app = require('@untool/express').createServer('serve');
const awsConfig = require('./lib/aws-config')(config);
const shouldIncludeStageInRequest =
trimSlashes(config.basePath).indexOf(awsConfig.stageName) === 0 &&
trimSlashes(config.assetPath).indexOf(awsConfig.stageName) === 0;
// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by serverless-http and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below, then redeploy.
const binaryMimeTypes = [
'application/javascript',
'application/json',
'application/octet-stream',
'application/xml',
'font/eot',
'font/opentype',
'font/otf',
'font/woff',
'font/woff2',
'image/jpeg',
'use strict';
process.env.NODE_ENV = 'production';
const serverlessHttp = require('serverless-http');
const config = require('hops-config');
const { trimSlashes } = require('pathifist');
const app = require('@untool/express').createServer('serve');
const awsConfig = require('./lib/aws-config')(config);
const shouldIncludeStageInRequest =
trimSlashes(config.basePath).indexOf(awsConfig.stageName) === 0 &&
trimSlashes(config.assetPath).indexOf(awsConfig.stageName) === 0;
// NOTE: If you get ERR_CONTENT_DECODING_FAILED in your browser, this is likely
// due to a compressed response (e.g. gzip) which has not been handled correctly
// by serverless-http and/or API Gateway. Add the necessary MIME types to
// binaryMimeTypes below, then redeploy.
const binaryMimeTypes = [
'application/javascript',
'application/json',
'application/octet-stream',
'application/xml',
'font/eot',
'font/opentype',
'font/otf',
'font/woff',
'font/woff2',
function generateFragmentTypes() {
var hopsConfig = require('hops-config');
var options = {
schemaFile: hopsConfig.graphqlSchemaFile,
graphqlUri: hopsConfig.graphqlUri,
headers: [],
};
return require('../lib/fragments')(options);
}
function createApp(options) {
var app = express();
app.use(utils.timings);
app.use(helmet());
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(
return new Promise(function(resolve, reject) {
var filename = getFileName(location);
console.log(
filename.replace(hopsConfig.buildDir, ''),
filesize(Buffer.byteLength(html))
);
mkdirp(path.dirname(filename), function(err) {
if (err) {
reject(err);
} else {
fs.writeFile(filename, html, function(err) {
err ? reject(err) : resolve();
});
}
});
});
}
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;
}, [])
)
function defaultCallback(error) {
if (error) {
console.error(error.stack.toString());
} else {
console.log(
'hops: Server listening at ' +
url.format({
protocol: hopsConfig.https ? 'https' : 'http',
hostname:
hopsConfig.host === '0.0.0.0' ? 'localhost' : hopsConfig.host,
port: hopsConfig.port,
pathname: hopsConfig.basePath,
})
);
}
}