Z User
phase7: MCP stdio smoke test (handshake + tools/list + get_roots 6:74) — 4/4 tests PASS
54a6341 Download node_modules/hono/dist/middleware/request-id/request-id.js from bravesigma/quran-md-plugin: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/datasets/bravesigma/quran-md-plugin/resolve/main/node_modules/hono/dist/middleware/request-id/request-id.js
- Command line
-
hf download hf://datasets/bravesigma/quran-md-plugin/node_modules/hono/dist/middleware/request-id/request-id.js
-
curl -L -o request-id.js https://huggingface.co/datasets/bravesigma/quran-md-plugin/resolve/main/node_modules/hono/dist/middleware/request-id/request-id.js
1.22 kB
| //#region src/middleware/request-id/request-id.ts | |
| /** | |
| * Request ID Middleware for Hono. | |
| * | |
| * @param {RequestIdOptions} [options] - Options for Request ID middleware. | |
| * @param {number} [options.limitLength=255] - The maximum length of request id. | |
| * @param {string} [options.headerName='X-Request-Id'] - The header name used in request id. | |
| * @param {(c: Context) => string} [options.generator=() => crypto.randomUUID()] - The request id generation function. | |
| * | |
| * @returns {MiddlewareHandler} The middleware handler function. | |
| * | |
| * @example | |
| * ```ts | |
| * type Variables = RequestIdVariables | |
| * const app = new Hono<{Variables: Variables}>() | |
| * | |
| * app.use(requestId()) | |
| * app.get('/', (c) => { | |
| * console.log(c.get('requestId')) // Debug | |
| * return c.text('Hello World!') | |
| * }) | |
| * ``` | |
| */ | |
| const requestId = ({ limitLength = 255, headerName = "X-Request-Id", generator = () => crypto.randomUUID() } = {}) => { | |
| return async function requestId(c, next) { | |
| let reqId = headerName ? c.req.header(headerName) : void 0; | |
| if (!reqId || reqId.length > limitLength || /[^\w\-=]/.test(reqId)) reqId = generator(c); | |
| c.set("requestId", reqId); | |
| if (headerName) c.header(headerName, reqId); | |
| await next(); | |
| }; | |
| }; | |
| //#endregion | |
| export { requestId }; | |