Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const defaultResponses = getDefaultResponses(isCorsEnabled)
updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
if (securityDefinition) {
updatedMethods = set(
[normalizedMethod, 'security'],
[{ [securityDefinition.name]: [] }],
updatedMethods
)
securityDefinitions[securityDefinition.name] = securityDefinition.definition
}
}, or(methods, {}))
if (enableCorsOnPath) {
const corsOptionsMethod = getCorsOptionsConfig()
updatedMethods = set('options', corsOptionsMethod, updatedMethods)
}
// set the paths
paths = set([normalizedPath], updatedMethods, paths)
}, or(routes, {}))
(accum, value, key) => {
value = resolve(value)
if (isSerializable(value)) {
if (isSymbol(key)) {
const symbolString = getSymbolString(context, key)
if (symbolString) {
if (isSerializableReferenceable(value)) {
return set(['symbols', symbolString], toReference(context, value), accum)
}
return set(['symbols', symbolString], serializeValue(context, value), accum)
}
// context.log(`unhandled symbol detected ${toString(key)}`)
} else {
if (isSerializableReferenceable(value)) {
return set(['props', key], toReference(context, value), accum)
}
return set(['props', key], serializeValue(context, value), accum)
}
}
return accum
},
{
const defaultResponses = getDefaultResponses(isCorsEnabled)
updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
if (securityDefinition) {
updatedMethods = set(
[normalizedMethod, 'security'],
[{ [securityDefinition.name]: [] }],
updatedMethods
)
securityDefinitions[securityDefinition.name] = securityDefinition.definition
}
}, or(methods, {}))
if (enableCorsOnPath) {
const corsOptionsMethod = getCorsOptionsConfig()
updatedMethods = set('options', corsOptionsMethod, updatedMethods)
}
// set the paths
paths = set([normalizedPath], updatedMethods, paths)
}, or(routes, {}))
'x-amazon-apigateway-integration': {
type: 'aws_proxy',
httpMethod: 'POST',
credentials: roleArn,
uri,
responses: {
default: {
statusCode: '200'
}
}
}
}
if (useCors) {
let apiGatewayIntegrationWithCors = { ...apiGatewayIntegration }
apiGatewayIntegrationWithCors = set(
['x-amazon-apigateway-integration', 'responses', 'default', 'responseParameters'],
{
'method.response.header.Access-Control-Allow-Headers':
"'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
'method.response.header.Access-Control-Allow-Methods': "'*'",
'method.response.header.Access-Control-Allow-Origin': "'*'"
},
apiGatewayIntegrationWithCors
)
return apiGatewayIntegrationWithCors
}
return apiGatewayIntegration
}
function getDefaultResponses(useCors) {
const defaultResponses = {
200: {
description: 'Success'
}
}
if (useCors) {
let defaultResponsesWithCors = { ...defaultResponses }
defaultResponsesWithCors = set(
[200],
{
headers: {
'Access-Control-Allow-Headers': {
type: 'string'
},
'Access-Control-Allow-Methods': {
type: 'string'
},
'Access-Control-Allow-Origin': {
type: 'string'
}
}
},
defaultResponsesWithCors
)
enableCorsOnPath = true
} else {
isCorsEnabled = false
}
const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
const securityDefinition = getSecurityDefinition(
methodObject.authorizer,
name,
undefined,
normalizedPath,
normalizedMethod
)
const defaultResponses = getDefaultResponses(isCorsEnabled)
updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
if (securityDefinition) {
updatedMethods = set(
[normalizedMethod, 'security'],
[{ [securityDefinition.name]: [] }],
updatedMethods
)
securityDefinitions[securityDefinition.name] = securityDefinition.definition
}
}, or(methods, {}))
isCorsEnabled = false
}
const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
const securityDefinition = getSecurityDefinition(
methodObject.authorizer,
name,
undefined,
normalizedPath,
normalizedMethod
)
const defaultResponses = getDefaultResponses(isCorsEnabled)
updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
if (securityDefinition) {
updatedMethods = set(
[normalizedMethod, 'security'],
[{ [securityDefinition.name]: [] }],
updatedMethods
)
securityDefinitions[securityDefinition.name] = securityDefinition.definition
}
}, or(methods, {}))
isCorsEnabled = true
enableCorsOnPath = true
} else {
isCorsEnabled = false
}
const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
const securityDefinition = getSecurityDefinition(
methodObject.authorizer,
name,
undefined,
normalizedPath,
normalizedMethod
)
const defaultResponses = getDefaultResponses(isCorsEnabled)
updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
if (securityDefinition) {
updatedMethods = set(
[normalizedMethod, 'security'],
[{ [securityDefinition.name]: [] }],
updatedMethods
)
securityDefinitions[securityDefinition.name] = securityDefinition.definition
}
}, or(methods, {}))
enableCorsOnPath = true
} else {
isCorsEnabled = false
}
const apiGatewayIntegration = getApiGatewayIntegration(roleArn, uri, isCorsEnabled)
const securityDefinition = getSecurityDefinition(
methodObject.authorizer,
name,
undefined,
normalizedPath,
normalizedMethod
)
const defaultResponses = getDefaultResponses(isCorsEnabled)
updatedMethods = set([normalizedMethod], apiGatewayIntegration, updatedMethods)
updatedMethods = set([normalizedMethod, 'responses'], defaultResponses, updatedMethods)
if (securityDefinition) {
updatedMethods = set(
[normalizedMethod, 'security'],
[{ [securityDefinition.name]: [] }],
updatedMethods
)
securityDefinitions[securityDefinition.name] = securityDefinition.definition
}
}, or(methods, {}))