Skip to content

Instantly share code, notes, and snippets.

@MattMS
Last active August 4, 2017 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattMS/bbccf2c6e5e9e7e0be11d38e7587ea14 to your computer and use it in GitHub Desktop.
Save MattMS/bbccf2c6e5e9e7e0be11d38e7587ea14 to your computer and use it in GitHub Desktop.

Compose Express calls

compose = (calls)-> (req, res, next)->
	if calls.length
		calls[0] req, res, ->
			call = compose calls.slice 1
			call req, res, next
	else if next
		next()

Test

a = (req, res, next)->
	console.log 'a'
	next()

b = (req, res, next)->
	console.log 'b'
	next()

c = (req, res, next)->
	console.log 'c'
	next()

compose([a, b, c]) 1, 2, ->
	console.log 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment