@octokit/webhooks
Advanced tools
| function normalizeTrailingSlashes(path) { | ||
| let i = path.length; | ||
| if (i === 0) { | ||
| return "/"; | ||
| } | ||
| while (i > 0) { | ||
| if (path.charCodeAt(--i) !== 47) { | ||
| break; | ||
| } | ||
| } | ||
| if (i === -1) { | ||
| return "/"; | ||
| } | ||
| return path.slice(0, i + 1); | ||
| } | ||
| export { | ||
| normalizeTrailingSlashes | ||
| }; |
| export declare function normalizeTrailingSlashes(path: string): string; |
+23
-2
@@ -546,2 +546,19 @@ // pkg/dist-src/create-logger.js | ||
| // pkg/dist-src/normalize-trailing-slashes.js | ||
| function normalizeTrailingSlashes(path) { | ||
| let i = path.length; | ||
| if (i === 0) { | ||
| return "/"; | ||
| } | ||
| while (i > 0) { | ||
| if (path.charCodeAt(--i) !== 47) { | ||
| break; | ||
| } | ||
| } | ||
| if (i === -1) { | ||
| return "/"; | ||
| } | ||
| return path.slice(0, i + 1); | ||
| } | ||
| // pkg/dist-src/middleware/create-middleware.js | ||
@@ -557,6 +574,10 @@ var isApplicationJsonRE = /^\s*(application\/json)\s*(?:;|$)/u; | ||
| return function middleware(webhooks, options2) { | ||
| const middlewarePath = normalizeTrailingSlashes(options2.path); | ||
| return async function octokitWebhooksMiddleware(request, response, next) { | ||
| let pathname; | ||
| try { | ||
| pathname = new URL(request.url, "http://localhost").pathname; | ||
| pathname = new URL( | ||
| normalizeTrailingSlashes(request.url), | ||
| "http://localhost" | ||
| ).pathname; | ||
| } catch (error) { | ||
@@ -574,3 +595,3 @@ return handleResponse3( | ||
| } | ||
| if (pathname !== options2.path) { | ||
| if (pathname !== middlewarePath) { | ||
| next?.(); | ||
@@ -577,0 +598,0 @@ return handleResponse3(null); |
@@ -0,1 +1,2 @@ | ||
| import { normalizeTrailingSlashes } from "../normalize-trailing-slashes.js"; | ||
| const isApplicationJsonRE = /^\s*(application\/json)\s*(?:;|$)/u; | ||
@@ -10,6 +11,10 @@ const WEBHOOK_HEADERS = [ | ||
| return function middleware(webhooks, options2) { | ||
| const middlewarePath = normalizeTrailingSlashes(options2.path); | ||
| return async function octokitWebhooksMiddleware(request, response, next) { | ||
| let pathname; | ||
| try { | ||
| pathname = new URL(request.url, "http://localhost").pathname; | ||
| pathname = new URL( | ||
| normalizeTrailingSlashes(request.url), | ||
| "http://localhost" | ||
| ).pathname; | ||
| } catch (error) { | ||
@@ -27,3 +32,3 @@ return handleResponse( | ||
| } | ||
| if (pathname !== options2.path) { | ||
| if (pathname !== middlewarePath) { | ||
| next?.(); | ||
@@ -30,0 +35,0 @@ return handleResponse(null); |
+2
-2
| { | ||
| "name": "@octokit/webhooks", | ||
| "version": "14.1.1", | ||
| "version": "14.1.2", | ||
| "description": "GitHub webhook events toolset for Node.js", | ||
@@ -24,3 +24,3 @@ "keywords": [], | ||
| "get-port": "^7.1.0", | ||
| "prettier": "3.5.3", | ||
| "prettier": "3.6.2", | ||
| "prettier-plugin-packagejson": "^2.2.9", | ||
@@ -27,0 +27,0 @@ "tsx": "^4.19.3", |
Sorry, the diff of this file is not supported yet
184223
1.03%51
4.08%2041
2.2%