UNPKG

@tsed/platform-http

Version:
12 lines (11 loc) 322 B
import { getContext, runInContext } from "@tsed/di"; export function ensureContext(request, cb, fallback) { const $ctx = getContext(); if ($ctx) { return cb($ctx); } if (!request?.$ctx && fallback) { return fallback(); } return runInContext(request.$ctx, () => cb(request.$ctx)); }