Skip to content

Commit c06500b

Browse files
committed
fix: address all review feedback
- Moved CorsOptions type to types/rest.ts - Moved DEFAULT_CORS_OPTIONS to constants.ts - Fixed middleware to mutate existing headers - Updated tests with Prepare/Act/Assess pattern - Removed example files (will add in docs PR) - Fixed all linting issues - Converted functions to arrow functions
1 parent 2a9fd4c commit c06500b

File tree

12 files changed

+608
-569
lines changed

12 files changed

+608
-569
lines changed

examples/snippets/event-handler/rest/cors_basic_usage.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

examples/snippets/event-handler/rest/cors_custom_config.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/snippets/event-handler/rest/cors_dynamic_origin.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/event-handler/src/appsync-events/Router.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { GenericLogger } from '@aws-lambda-powertools/commons/types';
22
import { isRecord } from '@aws-lambda-powertools/commons/typeutils';
3-
import { getStringFromEnv, isDevMode } from '@aws-lambda-powertools/commons/utils/env';
3+
import {
4+
getStringFromEnv,
5+
isDevMode,
6+
} from '@aws-lambda-powertools/commons/utils/env';
47
import type {
58
OnPublishHandler,
69
OnSubscribeHandler,
@@ -31,7 +34,7 @@ class Router {
3134
* Whether the router is running in development mode.
3235
*/
3336
protected readonly isDev: boolean = false;
34-
37+
3538
public constructor(options?: RouterOptions) {
3639
const alcLogLevel = getStringFromEnv({
3740
key: 'AWS_LAMBDA_LOG_LEVEL',

packages/event-handler/src/appsync-graphql/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export { AppSyncGraphQLResolver } from './AppSyncGraphQLResolver.js';
22
export {
3-
ResolverNotFoundException,
43
InvalidBatchResponseException,
4+
ResolverNotFoundException,
55
} from './errors.js';
66
export {
77
awsDate,

packages/event-handler/src/rest/constants.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,20 @@ export const PARAM_PATTERN = /:([a-zA-Z_]\w*)(?=\/|$)/g;
8787
export const SAFE_CHARS = "-._~()'!*:@,;=+&$";
8888

8989
export const UNSAFE_CHARS = '%<> \\[\\]{}|^';
90+
91+
/**
92+
* Default CORS configuration
93+
*/
94+
export const DEFAULT_CORS_OPTIONS = {
95+
origin: '*',
96+
allowMethods: ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'],
97+
allowHeaders: [
98+
'Authorization',
99+
'Content-Type',
100+
'X-Amz-Date',
101+
'X-Api-Key',
102+
'X-Amz-Security-Token',
103+
],
104+
exposeHeaders: [],
105+
credentials: false,
106+
} as const;

0 commit comments

Comments
 (0)