-
Notifications
You must be signed in to change notification settings - Fork 24
/
index.ts
29 lines (26 loc) · 926 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import awsServerlessExpress from "aws-serverless-express";
import { APIGatewayProxyEvent, Context } from "aws-lambda";
import { enableLiteMode, dbUrl, defaultLocalPort } from "./config";
import { app } from "./app";
import { logger } from "./helpers/logger";
import {
connectToMongoMemoryServer,
connectToRemoteMongo,
} from "./helpers/mongo";
// Connecting to mongoDB
if (enableLiteMode) {
connectToMongoMemoryServer();
} else {
connectToRemoteMongo(dbUrl);
}
// Exporting method for docker container for AWS lambda
const server = awsServerlessExpress.createServer(app);
export const handler = (event: APIGatewayProxyEvent, context: Context) =>
awsServerlessExpress.proxy(server, event, context);
// Method for locals server execution
export const runLocalServer = () => {
const port = defaultLocalPort;
app.listen(port, () => {
logger.info(`Express api listening at http://localhost:${port}`);
});
};