diff --git a/packages/api/src/adapter-aws/AwsApiGatewayAdapter.test.ts b/packages/api/src/adapter-aws/AwsApiGatewayAdapter.test.ts index e7f8d1d..6c2cf50 100644 --- a/packages/api/src/adapter-aws/AwsApiGatewayAdapter.test.ts +++ b/packages/api/src/adapter-aws/AwsApiGatewayAdapter.test.ts @@ -310,6 +310,24 @@ describe('AwsApiGatewayAdapter', () => { expect((lambdaCommands[0] as RemovePermissionCommand).input).toMatchObject({FunctionName: 'hello', StatementId: 'apigateway-a1b2c3-dev-POST-hello'}) }) + test('deletes a CORS OPTIONS method and redeploys its stage', async () => { + const commands: unknown[] = [] + const adapter = new AwsApiGatewayAdapter(fakeClient((command) => { + commands.push(command) + if (command instanceof GetMethodCommand) { + return {methodIntegration: {type: 'MOCK'}} + } + return {} + }), fakeLambda(() => ({}))) + + await adapter.deleteApiGatewayRoute('a1b2c3', {resourceId: 'resource456', path: '/hello', method: 'OPTIONS', stage: 'dev'}) + + expect(commands.map((command) => (command as {constructor: {name: string}}).constructor.name)).toEqual([ + 'GetMethodCommand', 'DeleteMethodCommand', 'CreateDeploymentCommand', + ]) + expect((commands[1] as DeleteMethodCommand).input).toMatchObject({httpMethod: 'OPTIONS'}) + }) + test('enables CORS for non-proxy methods, creates OPTIONS, and reports proxy methods', async () => { const commands: unknown[] = [] const adapter = new AwsApiGatewayAdapter(fakeClient((command) => { diff --git a/packages/api/src/adapter-aws/AwsApiGatewayAdapter.ts b/packages/api/src/adapter-aws/AwsApiGatewayAdapter.ts index 95f85cf..052703b 100644 --- a/packages/api/src/adapter-aws/AwsApiGatewayAdapter.ts +++ b/packages/api/src/adapter-aws/AwsApiGatewayAdapter.ts @@ -220,7 +220,7 @@ export class AwsApiGatewayAdapter implements CloudServiceAdapter { async deleteApiGatewayRoute(apiId: string, input: ApiGatewayDeleteRouteInput): Promise { const method = input.method.toUpperCase() const stage = stageName(input.stage) - if (!['GET', 'POST', 'PUT', 'DELETE'].includes(method)) throw new ValidationError('method must be GET, POST, PUT, or DELETE') + if (!CORS_METHODS.includes(method)) throw new ValidationError('method must be GET, POST, PUT, DELETE, or OPTIONS') if (!stringValue(input.resourceId)) throw new ValidationError('resourceId is required') const route = await this.apiGateway.send(new GetMethodCommand({