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

Commit

Permalink
fix(serverless): add experimental support for aws #5 and google cloud #6
Browse files Browse the repository at this point in the history
  • Loading branch information
nahtnam committed May 1, 2019
1 parent 924dbbf commit fcc5405
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"homepage": "https://github.com/ludicrousxyz/light#readme",
"dependencies": {
"aws-serverless-micro": "^1.0.2",
"chokidar": "^2.1.5",
"colorette": "^1.0.7",
"emojic": "^1.1.15",
Expand Down
21 changes: 20 additions & 1 deletion src/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { run } from 'micro';
import { IncomingMessage, ServerResponse } from 'http';
import AWSServerlessMicro from 'aws-serverless-micro';
import pino from 'pino-http';

interface Route {
Expand All @@ -8,7 +9,8 @@ interface Route {
handler: Handler;
}

type Handler = (req: IncomingMessage, res: ServerResponse) => {};
// TODO: Define types for micro and aws
type Handler = any;
type IM = IncomingMessage;
type SR = ServerResponse;
type AP = Promise<any>;
Expand Down Expand Up @@ -37,5 +39,22 @@ export default (route: Route): Handler => {
fn.path = route.path;
fn.log = true;
fn.module = __dirname;

const isAWS: boolean = !!(
(process.env.LAMBDA_TASK_ROOT && process.env.AWS_EXECUTION_ENV) || false
);
if (isAWS) {
return {
handler: AWSServerlessMicro(fn),
};
}

const isGCP: boolean = !!(process.env.X_GOOGLE_FUNCTION_NAME || false);
if (isGCP) {
return {
handler: fn,
};
}

return fn;
};
1 change: 1 addition & 0 deletions src/types/aws-serverless-micro.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'aws-serverless-micro';

0 comments on commit fcc5405

Please sign in to comment.