-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: return 404 for unknown routes (#341)
BREAKING CHANGE: drop `onUnhandledRequest` middleware option
- Loading branch information
Showing
13 changed files
with
181 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,23 @@ | ||
import { parseRequest } from "./api-gateway-v2-parse-request"; | ||
import { sendResponse } from "./api-gateway-v2-send-response"; | ||
import { handleRequest } from "../handle-request"; | ||
import { onUnhandledRequestDefault } from "../on-unhandled-request-default"; | ||
import { HandlerOptions } from "../types"; | ||
import { OAuthApp } from "../../index"; | ||
import { Options, ClientType } from "../../types"; | ||
import type { HandlerOptions } from "../types"; | ||
import type { OAuthApp } from "../../index"; | ||
import type { ClientType, Options } from "../../types"; | ||
import type { | ||
APIGatewayProxyEventV2, | ||
APIGatewayProxyStructuredResultV2, | ||
} from "aws-lambda"; | ||
|
||
async function onUnhandledRequestDefaultAWSAPIGatewayV2( | ||
event: APIGatewayProxyEventV2 | ||
): Promise<APIGatewayProxyStructuredResultV2> { | ||
const request = parseRequest(event); | ||
const response = onUnhandledRequestDefault(request); | ||
return sendResponse(response); | ||
} | ||
|
||
export function createAWSLambdaAPIGatewayV2Handler( | ||
app: OAuthApp<Options<ClientType>>, | ||
{ | ||
pathPrefix, | ||
onUnhandledRequest = onUnhandledRequestDefaultAWSAPIGatewayV2, | ||
}: HandlerOptions & { | ||
onUnhandledRequest?: ( | ||
event: APIGatewayProxyEventV2 | ||
) => Promise<APIGatewayProxyStructuredResultV2>; | ||
} = {} | ||
options: HandlerOptions = {} | ||
) { | ||
return async function (event: APIGatewayProxyEventV2) { | ||
return async function ( | ||
event: APIGatewayProxyEventV2 | ||
): Promise<APIGatewayProxyStructuredResultV2 | undefined> { | ||
const request = parseRequest(event); | ||
const response = await handleRequest(app, { pathPrefix }, request); | ||
return response ? sendResponse(response) : onUnhandledRequest(event); | ||
const response = await handleRequest(app, options, request); | ||
return response ? sendResponse(response) : undefined; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
...iddleware/on-unhandled-request-default.ts → src/middleware/unknown-route-response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,17 @@ | ||
import { parseRequest } from "./parse-request"; | ||
import { sendResponse } from "./send-response"; | ||
import { handleRequest } from "../handle-request"; | ||
import { onUnhandledRequestDefault } from "../on-unhandled-request-default"; | ||
import { OAuthApp } from "../../index"; | ||
import { HandlerOptions } from "../types"; | ||
import { ClientType, Options } from "../../types"; | ||
|
||
async function onUnhandledRequestDefaultWebWorker( | ||
request: Request | ||
): Promise<Response> { | ||
const octokitRequest = parseRequest(request); | ||
const octokitResponse = onUnhandledRequestDefault(octokitRequest); | ||
return sendResponse(octokitResponse); | ||
} | ||
import type { OAuthApp } from "../../index"; | ||
import type { HandlerOptions } from "../types"; | ||
import type { ClientType, Options } from "../../types"; | ||
|
||
export function createWebWorkerHandler<T extends Options<ClientType>>( | ||
app: OAuthApp<T>, | ||
{ | ||
pathPrefix, | ||
onUnhandledRequest = onUnhandledRequestDefaultWebWorker, | ||
}: HandlerOptions & { | ||
onUnhandledRequest?: (request: Request) => Response | Promise<Response>; | ||
} = {} | ||
options: HandlerOptions = {} | ||
) { | ||
return async function (request: Request): Promise<Response> { | ||
const octokitRequest = parseRequest(request); | ||
const octokitResponse = await handleRequest( | ||
app, | ||
{ pathPrefix }, | ||
octokitRequest | ||
); | ||
return octokitResponse | ||
? sendResponse(octokitResponse) | ||
: await onUnhandledRequest(request); | ||
return async function (request: Request): Promise<Response | undefined> { | ||
const octokitRequest = await parseRequest(request); | ||
const octokitResponse = await handleRequest(app, options, octokitRequest); | ||
return octokitResponse ? sendResponse(octokitResponse) : undefined; | ||
}; | ||
} | ||
|
||
/** @deprecated */ | ||
export function createCloudflareHandler<T>( | ||
...args: Parameters<typeof createWebWorkerHandler> | ||
) { | ||
args[0].octokit.log.warn( | ||
"[@octokit/oauth-app] `createCloudflareHandler` is deprecated, use `createWebWorkerHandler` instead" | ||
); | ||
return createWebWorkerHandler(...args); | ||
} |
Oops, something went wrong.