UNPKG

@trpc/server

Version:

The tRPC server library

31 lines (29 loc) • 1.04 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const require_codes = require("../codes-Be-DrYMh.cjs"); const require_getErrorShape = require("../getErrorShape-BAuHhNuh.cjs"); const require_node_http = require("../node-http-vS2eeV-2.cjs"); //#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 = ""; require_codes.run(async () => { path = req.path.slice(req.path.lastIndexOf("/") + 1); await require_node_http.nodeHTTPRequestHandler(require_getErrorShape._objectSpread2(require_getErrorShape._objectSpread2({}, opts), {}, { req, res, path })); }).catch(require_node_http.internal_exceptionHandler(require_getErrorShape._objectSpread2({ req, res, path }, opts))); }; } //#endregion exports.createExpressMiddleware = createExpressMiddleware;