Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
fix(route): properly export run based on the environment
Browse files Browse the repository at this point in the history
  • Loading branch information
nahtnam committed May 25, 2019
1 parent 82351fd commit 387d660
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const youchErrors = (fun: any): any => async (req: IM, res: SR): Promise<void> =
};

export default (route: Route): Handler => {
const fn = async (Req: IM, Res: SR): AP => {
const proxy = async (Req: IM, Res: SR): AP => {
let exec = async (req: IM, res: SR): AP => {
const middleware: any[] = route.middleware || [];

Expand All @@ -111,9 +111,9 @@ export default (route: Route): Handler => {

const plugins = route.plugins || [];

if ((fn as any).log !== false) {
if ((proxy as any).log !== false) {
plugins.unshift(logger);
(fn as any).log = false;
(proxy as any).log = false;
}

/* istanbul ignore next */
Expand All @@ -130,19 +130,24 @@ export default (route: Route): Handler => {
return exec(Req, Res);
};

let fn = proxy;

Object.keys(route).forEach((key): void => {
(fn as any)[key] = (route as any)[key];
});
(fn as any).handler = proxy;

(fn as any).log = true;
(fn as any).module = __dirname;
(fn as any).handler = fn;
/* istanbul ignore next */
if (!isNetlify && !isAWS) {
(fn as any).handler = async (req: IM, res: SR): AP => run(req, res, fn);
fn = async (req, res): AP => run(req, res, proxy);
Object.keys(route).forEach((key): void => {
(fn as any)[key] = (route as any)[key];
});
(fn as any).handler = async (req: IM, res: SR): AP => run(req, res, proxy);
}

(fn as any).log = true;
(fn as any).module = __dirname;

/* istanbul ignore if */
if (isNetlify || isAWS) {
return {
Expand Down

0 comments on commit 387d660

Please sign in to comment.