Spaces:
Paused
Paused
Download src/proxy/middleware/request/preprocess.ts from cyclinghearttortoise/STE: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/cyclinghearttortoise/STE/resolve/main/src/proxy/middleware/request/preprocess.ts
- Command line
-
hf download hf://spaces/cyclinghearttortoise/STE/src/proxy/middleware/request/preprocess.ts
-
curl -L -o preprocess.ts https://huggingface.co/spaces/cyclinghearttortoise/STE/resolve/main/src/proxy/middleware/request/preprocess.ts
1 kB
| import { RequestHandler } from "express"; | |
| import { handleInternalError } from "../common"; | |
| import { RequestPreprocessor, setApiFormat, transformOutboundPayload } from "."; | |
| /** | |
| * Returns a middleware function that processes the request body into the given | |
| * API format, and then sequentially runs the given additional preprocessors. | |
| */ | |
| export const createPreprocessorMiddleware = ( | |
| apiFormat: Parameters<typeof setApiFormat>[0], | |
| additionalPreprocessors?: RequestPreprocessor[] | |
| ): RequestHandler => { | |
| const preprocessors: RequestPreprocessor[] = [ | |
| setApiFormat(apiFormat), | |
| transformOutboundPayload, | |
| ...(additionalPreprocessors ?? []), | |
| ]; | |
| return async function executePreprocessors(req, res, next) { | |
| try { | |
| for (const preprocessor of preprocessors) { | |
| await preprocessor(req); | |
| } | |
| next(); | |
| } catch (error) { | |
| req.log.error(error, "Error while executing request preprocessor"); | |
| handleInternalError(error as Error, req, res); | |
| } | |
| }; | |
| }; | |