Created
April 27, 2021 23:49
-
-
Save gufranco/08ba1f6be23fb3a37012e919d81de8b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Express, Request, Response } from 'express' | |
import bodyParser from 'body-parser' | |
import dotenv from 'dotenv-safe' | |
import prettyError from 'pretty-error' | |
import { handler } from './src/app' | |
import { SQSPayloadInterface } from './src/interfaces/PayloadInterface' | |
prettyError.start() | |
dotenv.config() | |
const httpServer: Express = express() | |
httpServer.use(bodyParser.json()) | |
httpServer.use(bodyParser.urlencoded({ extended: true })) | |
httpServer.post('/', async (request: Request, response: Response) => { | |
const sqsPayload: SQSPayloadInterface = request.body | |
try { | |
await handler(sqsPayload) | |
response.status(200).send() | |
} catch (exception) { | |
console.error(exception) | |
response.status(500).json(exception) | |
} | |
}) | |
httpServer.listen(process.env.EXPRESS_HTTP_PORT as string, () => { | |
console.log( | |
`Development environment is up and running at http://localhost:${ | |
process.env.EXPRESS_HTTP_PORT as string | |
}`, | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment