Skip to content

Commit c653b6e

Browse files
committed
changed the RequestContext request property to the shortened req
1 parent f27c945 commit c653b6e

File tree

8 files changed

+14
-16
lines changed

8 files changed

+14
-16
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class Router {
166166
* ```typescript
167167
* const authMiddleware: Middleware = async ({params, reqCtx, next}) => {
168168
* // Authentication logic
169-
* if (!isAuthenticated(reqCtx.request)) {
169+
* if (!isAuthenticated(reqCtx.req)) {
170170
* return new Response('Unauthorized', { status: 401 });
171171
* }
172172
* await next();
@@ -215,19 +215,19 @@ class Router {
215215
};
216216
}
217217

218-
const request = proxyEventToWebRequest(event);
218+
const req = proxyEventToWebRequest(event);
219219

220220
const requestContext: RequestContext = {
221221
event,
222222
context,
223-
request,
223+
req,
224224
// this response should be overwritten by the handler, if it isn't
225225
// it means something went wrong with the middleware chain
226226
res: new Response('', { status: 500 }),
227227
};
228228

229229
try {
230-
const path = new URL(request.url).pathname as Path;
230+
const path = new URL(req.url).pathname as Path;
231231

232232
const route = this.routeRegistry.resolve(method, path);
233233

packages/event-handler/src/rest/middleware/compress.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ const compress = (options?: CompressionOptions): Middleware => {
7070
return async ({ reqCtx, next }) => {
7171
await next();
7272

73-
if (
74-
!shouldCompress(reqCtx.request, reqCtx.res, preferredEncoding, threshold)
75-
) {
73+
if (!shouldCompress(reqCtx.req, reqCtx.res, preferredEncoding, threshold)) {
7674
return;
7775
}
7876

packages/event-handler/src/rest/middleware/cors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ export const cors = (options?: CorsOptions): Middleware => {
9797
};
9898

9999
return async ({ reqCtx, next }) => {
100-
const requestOrigin = reqCtx.request.headers.get('Origin');
100+
const requestOrigin = reqCtx.req.headers.get('Origin');
101101
if (!isOriginAllowed(requestOrigin)) {
102102
await next();
103103
return;
104104
}
105105

106106
// Handle preflight OPTIONS request
107-
if (reqCtx.request.method === HttpVerbs.OPTIONS) {
108-
if (!isValidPreflightRequest(reqCtx.request.headers)) {
107+
if (reqCtx.req.method === HttpVerbs.OPTIONS) {
108+
if (!isValidPreflightRequest(reqCtx.req.headers)) {
109109
await next();
110110
return;
111111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ErrorResponse = {
1515
};
1616

1717
type RequestContext = {
18-
request: Request;
18+
req: Request;
1919
event: APIGatewayProxyEvent;
2020
context: Context;
2121
res: Response;

packages/event-handler/tests/unit/rest/Router/basic-routing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('Class: Router - Basic Routing', () => {
9191

9292
app.get('/test', async (_params, reqCtx) => {
9393
return {
94-
hasRequest: reqCtx.request instanceof Request,
94+
hasRequest: reqCtx.req instanceof Request,
9595
hasEvent: reqCtx.event === testEvent,
9696
hasContext: reqCtx.context === context,
9797
};

packages/event-handler/tests/unit/rest/Router/decorators.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ describe('Class: Router - Decorators', () => {
400400
@app.get('/test')
401401
public async getTest(_params: any, reqCtx: any) {
402402
return {
403-
hasRequest: reqCtx.request instanceof Request,
403+
hasRequest: reqCtx.req instanceof Request,
404404
hasEvent: reqCtx.event === testEvent,
405405
hasContext: reqCtx.context === context,
406406
};
@@ -435,7 +435,7 @@ describe('Class: Router - Decorators', () => {
435435
statusCode: HttpErrorCodes.BAD_REQUEST,
436436
error: 'Bad Request',
437437
message: error.message,
438-
hasRequest: reqCtx.request instanceof Request,
438+
hasRequest: reqCtx.req instanceof Request,
439439
hasEvent: reqCtx.event === testEvent,
440440
hasContext: reqCtx.context === context,
441441
};

packages/event-handler/tests/unit/rest/Router/error-handling.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ describe('Class: Router - Error Handling', () => {
375375
statusCode: HttpErrorCodes.BAD_REQUEST,
376376
error: 'Bad Request',
377377
message: error.message,
378-
hasRequest: reqCtx.request instanceof Request,
378+
hasRequest: reqCtx.req instanceof Request,
379379
hasEvent: reqCtx.event === testEvent,
380380
hasContext: reqCtx.context === context,
381381
}));

packages/event-handler/tests/unit/rest/Router/middleware.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe('Class: Router - Middleware', () => {
154154
expect(middlewareParams).toEqual({ id: '123' });
155155
expect(middlewareOptions?.event).toBe(testEvent);
156156
expect(middlewareOptions?.context).toBe(context);
157-
expect(middlewareOptions?.request).toBeInstanceOf(Request);
157+
expect(middlewareOptions?.req).toBeInstanceOf(Request);
158158
});
159159

160160
it('returns error response when next() is called multiple times', async () => {

0 commit comments

Comments
 (0)