Skip to content

Instantly share code, notes, and snippets.

@gufranco
Created April 27, 2021 23:49
Show Gist options
  • Save gufranco/08ba1f6be23fb3a37012e919d81de8b2 to your computer and use it in GitHub Desktop.
Save gufranco/08ba1f6be23fb3a37012e919d81de8b2 to your computer and use it in GitHub Desktop.
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