Last active
April 25, 2020 17:00
-
-
Save joandvgv/bfc6734edbbff3b61883e90fc3cd87ee to your computer and use it in GitHub Desktop.
Map API Gateway to an express server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from "express"; | |
import * as handlers from "./express-handler"; | |
import { connector } from "swagger-routes-express"; | |
import { apis, apiKeys } from "./constants"; | |
import { getExport } from "./api-gateway"; | |
import { setOperationIds } from "./utils"; | |
import { ApiDefinition } from "./types"; | |
const makeApp = (): express.Express => { | |
const app = express(); | |
app.use(express.json()); // allow json body | |
apis.forEach(async name => { | |
const key = apiKeys[name]; | |
const { body } = await getExport(key); // get api definition Buffer | |
const rawDefinition: ApiDefinition = JSON.parse(body.toString()); | |
const apiDefinition = setOperationIds(rawDefinition); // add operation ids according to each lambda | |
const connect = connector(handlers, apiDefinition, { onCreateRoute }); | |
connect(app); // attach the routes | |
}); | |
return app; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment