-
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.
refactor!: remove onUnhandledRequest middleware option
- Loading branch information
Showing
13 changed files
with
184 additions
and
378 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
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,53 +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, | ||
}: HandlerOptions & { | ||
onUnhandledRequest?: (request: Request) => Response | Promise<Response>; | ||
} = {} | ||
options: HandlerOptions = {} | ||
) { | ||
if (onUnhandledRequest) { | ||
app.octokit.log.warn( | ||
"[@octokit/oauth-app] `onUnhandledRequest` is deprecated and will be removed from the next major version." | ||
); | ||
} | ||
onUnhandledRequest ??= onUnhandledRequestDefaultWebWorker; | ||
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.