UNPKG

@trpc/server

Version:

The tRPC server library

31 lines (29 loc) • 894 B
import { m as run } from "../codes-nbrm_zWY.mjs"; import { n as _objectSpread2 } from "../getErrorShape-B5jPKHJ3.mjs"; import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-Df_b1FfK.mjs"; //#region src/adapters/express.ts /** * Creates an Express middleware that serves a router. Mount it on a path, * such as `/trpc`. * @see https://trpc.io/docs/server/adapters/express#3-use-the-express-adapter */ function createExpressMiddleware(opts) { return (req, res) => { let path = ""; run(async () => { path = req.path.slice(req.path.lastIndexOf("/") + 1); await nodeHTTPRequestHandler(_objectSpread2(_objectSpread2({}, opts), {}, { req, res, path })); }).catch(internal_exceptionHandler(_objectSpread2({ req, res, path }, opts))); }; } //#endregion export { createExpressMiddleware }; //# sourceMappingURL=express.mjs.map