Skip to content

Instantly share code, notes, and snippets.

@albinekb albinekb/wrapper.ts
Last active Sep 12, 2018

What would you like to do?
express async route wrapper
type Method = 'get' | 'post' | 'put' | 'delete'
type Handler = (req: Request) => Promise<any>
function route (method: Method, path: string, handler: Handler) {
app[method](path, (req, res, next) => {
.then(result => result ? res.json(result) : res.status(204).end(''))
route('post', '/test', async () => {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.