Skip to content

Commit cc6cdc1

Browse files
committed
fix cors bug
1 parent cf7aadd commit cc6cdc1

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

lib/apiGateway/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const _ = require('lodash')
66
module.exports = {
77
async validateServiceProxies() {
88
const events = []
9+
const corsPreflight = {}
910
await BbPromise.all(
1011
this.getAllServiceProxies().map(async (serviceProxy) => {
1112
Object.keys(serviceProxy).forEach(async (functionName) => {
1213
await this.checkAllowedService(functionName)
13-
const corsPreflight = []
1414
const http = serviceProxy[functionName]
1515
http.path = await this.getProxyPath(serviceProxy[functionName])
1616
http.method = await this.getProxyMethod(serviceProxy[functionName])
@@ -40,7 +40,7 @@ module.exports = {
4040
)
4141
return {
4242
events,
43-
corsPreflight: {}
43+
corsPreflight
4444
}
4545
},
4646

lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const validate = require('./apiGateway/validate')
88
const methods = require('./apiGateway/methods')
99
const compileRestApi = require('serverless/lib/plugins/aws/package/compile/events/apiGateway/lib/restApi')
1010
const compileResources = require('serverless/lib/plugins/aws/package/compile/events/apiGateway/lib/resources')
11+
const compileCors = require('serverless/lib/plugins/aws/package/compile/events/apiGateway/lib/cors')
1112
const compileDeployment = require('serverless/lib/plugins/aws/package/compile/events/apiGateway/lib/deployment')
1213
const getStackInfo = require('serverless/lib/plugins/aws/info/getStackInfo')
1314
// Kinesis
@@ -29,12 +30,14 @@ class ServerlessApigatewayServiceProxy {
2930
this.service = this.serverless.service.service
3031
this.region = this.provider.getRegion()
3132
this.stage = this.provider.getStage()
33+
this.apiGatewayMethodLogicalIds = []
3234
Object.assign(
3335
this,
3436
compileRestApi,
3537
compileResources,
3638
compileMethodsToKinesis,
3739
compileIamRoleToKinesis,
40+
compileCors,
3841
compileDeployment,
3942
validateKinesisServiceProxy,
4043
compileKinesisServiceProxy,
@@ -53,13 +56,13 @@ class ServerlessApigatewayServiceProxy {
5356
this.validated = await this.validateServiceProxies()
5457
await this.compileRestApi()
5558
await this.compileResources()
59+
await this.compileCors()
5660

5761
//Kinesis proxy
5862
await this.compileKinesisServiceProxy()
5963

6064
// SQS getProxy
6165
await this.compileSqsServiceProxy()
62-
6366
if (await this.existsDeployment()) {
6467
await this.compileDeployment()
6568
}

lib/package/kinesis/compileMethodsToKinesis.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const _ = require('lodash')
55

66
module.exports = {
77
async compileMethodsToKinesis() {
8-
this.apiGatewayMethodLogicalIds = []
98
this.validated.events.forEach(async (event) => {
109
if (event.functionName == 'kinesis') {
1110
const resourceId = this.getResourceId(event.http.path)

lib/package/sqs/compileMethodsToSqs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const _ = require('lodash')
55

66
module.exports = {
77
async compileMethodsToSqs() {
8-
this.apiGatewayMethodLogicalIds = []
98
this.validated.events.forEach(async (event) => {
109
if (event.functionName == 'sqs') {
1110
const resourceId = this.getResourceId(event.http.path)

0 commit comments

Comments
 (0)