Skip to content

Commit

Permalink
refactor(middleware)!: remove aws-lambda handler
Browse files Browse the repository at this point in the history
  • Loading branch information
baoshan committed Aug 31, 2022
1 parent 0e0853e commit 7ddb30b
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 265 deletions.
90 changes: 0 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1055,96 +1055,6 @@ function onUnhandledRequest(request) {
</tbody>
</table>

### `createAWSLambdaAPIGatewayV2Handler(app, options)`

Event handler for AWS Lambda using API Gateway V2 HTTP integration.

```js
// worker.js
import {
OAuthApp,
createAWSLambdaAPIGatewayV2Handler,
} from "@octokit/oauth-app";
const app = new OAuthApp({
clientType: "oauth-app",
clientId: "1234567890abcdef1234",
clientSecret: "1234567890abcdef1234567890abcdef12345678",
});

export const handler = createAWSLambdaAPIGatewayV2Handler(app, {
pathPrefix: "/api/github/oauth",
});

// can now receive user authorization callbacks at /api/github/oauth/callback
```

<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>app</code>
</th>
<th>
<code>OAuthApp instance</code>
</th>
<td>
<strong>Required</strong>.
</td>
</tr>
<tr>
<th>
<code>options.pathPrefix</code>
</th>
<th>
<code>string</code>
</th>
<td>

All exposed paths will be prefixed with the provided prefix. Defaults to `"/api/github/oauth"`

</td>
</tr>
<tr>
<th>
<code>options.onUnhandledRequest</code>
</th>
<th>
<code>function</code>
</th>
<td>Defaults to returns:

```js
function onUnhandledRequest(request) {
return
{
status: 404,
headers: { "content-type": "application/json" },
body: JSON.stringify({
error: `Unknown route: [METHOD] [URL]`,
})
}
);
}
```

</td>
</tr>
</tbody>
</table>

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@octokit/core": "^4.0.0",
"@octokit/oauth-authorization-url": "^5.0.0",
"@octokit/oauth-methods": "^2.0.0",
"@types/aws-lambda": "^8.10.83",
"fromentries": "^1.3.1",
"universal-user-agent": "^6.0.0"
},
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,22 @@ import type {
Options,
State,
} from "./types";

// types required by external middlewares (aws-lambda, etc)
export type {
HandlerOptions,
OctokitRequest,
OctokitResponse,
} from "./middleware/types";

// generic handlers
export { handleRequest } from "./middleware/handle-request";

export { createNodeMiddleware } from "./middleware/node/index";
export {
createCloudflareHandler,
createWebWorkerHandler,
} from "./middleware/web-worker/index";
export { createAWSLambdaAPIGatewayV2Handler } from "./middleware/aws-lambda/api-gateway-v2";

type Constructor<T> = new (...args: any[]) => T;

Expand Down
1 change: 0 additions & 1 deletion src/middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ middleware
├── types.ts
├── node/
├── web-worker/ (Cloudflare Workers & Deno)
└── deno/ (to be implemented)
```

## Generic HTTP Handler
Expand Down
13 changes: 0 additions & 13 deletions src/middleware/aws-lambda/api-gateway-v2-parse-request.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/middleware/aws-lambda/api-gateway-v2-send-response.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/middleware/aws-lambda/api-gateway-v2.ts

This file was deleted.

109 changes: 0 additions & 109 deletions test/aws-lambda-api-gateway-v2.test.ts

This file was deleted.

6 changes: 5 additions & 1 deletion test/smoke.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OAuthApp } from "../src";
import { handleRequest, OAuthApp } from "../src";

describe("Smoke test", () => {
it("OAuthApp is a function", () => {
Expand All @@ -12,4 +12,8 @@ describe("Smoke test", () => {
it("OAuthApp.VERSION is set", () => {
expect(OAuthApp.VERSION).toEqual("0.0.0-development");
});

it("exports generic handler for external middlewares", () => {
expect(typeof handleRequest).toBe("function");
});
});

0 comments on commit 7ddb30b

Please sign in to comment.