Skip to content

Commit

Permalink
fix(): fallback to request property when req does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Nov 10, 2020
1 parent 20886eb commit f557407
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/utils/merge-defaults.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ export function mergeDefaults(
...options,
};
if (!moduleOptions.context) {
moduleOptions.context = ({ req }) => ({ req });
moduleOptions.context = ({ req, request }) => ({ req: req ?? request });
} else if (isFunction(moduleOptions.context)) {
moduleOptions.context = async (...args: unknown[]) => {
const ctx = await (options.context as Function)(...args);
const { req } = args[0] as Record<string, unknown>;
return assignReqProperty(ctx, req);
const { req, request } = args[0] as Record<string, unknown>;
return assignReqProperty(ctx, req ?? request);
};
} else {
moduleOptions.context = ({ req }: Record<string, unknown>) => {
return assignReqProperty(options.context as Record<string, any>, req);
moduleOptions.context = ({ req, request }: Record<string, unknown>) => {
return assignReqProperty(
options.context as Record<string, any>,
req ?? request,
);
};
}
return moduleOptions;
Expand Down

0 comments on commit f557407

Please sign in to comment.