Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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 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,
})
);
}
}
function defaultCallback(error, server) {
if (error) {
console.error(error.stack ? error.stack.toString() : error.toString());
} else {
var address = server.address();
console.log(
'hops: Server listening at ' +
url.format({
protocol: hopsConfig.https ? 'https' : 'http',
hostname:
address.address === '0.0.0.0' ? 'localhost' : address.address,
port: address.port,
pathname: hopsConfig.basePath,
})
);
}
}
var location = hopsConfig.locations.find(function(location) {
return (
location !== hopsConfig.basePath + '/' &&
req.url.indexOf(location) === 0
);
});
if (location) {
var location = hopsConfig.locations.find(function(location) {
return (
location !== hopsConfig.basePath + '/' &&
req.url.indexOf(location) === 0
);
});
if (location) {
exports.ReactContext = function(options) {
if (!options) {
options = {};
}
this.routerOptions = Object.assign(
{ basename: hopsConfig.basePath },
options.router
);
this.mountpoint = options.mountpoint || '#main';
};
exports.ReactContext.prototype = {
exports.ReactContext = function(options) {
if (!options) {
options = {};
}
this.routerOptions = Object.assign(
{
location: options.request && options.request.path,
basename: hopsConfig.basePath,
context: {},
},
options.router
);
this.template = options.template || defaultTemplate;
this.assets = options.response && options.response.locals.hops.assets;
};
exports.ReactContext.prototype = {