@trpc/server
Version:
30 lines (28 loc) • 874 B
JavaScript
import { m as run } from "../codes-BCsCCyMj.mjs";
import { n as nodeHTTPRequestHandler, t as internal_exceptionHandler } from "../node-http-5y0OmcF3.mjs";
import { n as _objectSpread2 } from "../getErrorShape-CVrl8_-w.mjs";
// 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)));
};
}
export { createExpressMiddleware };
//# sourceMappingURL=express.mjs.map