Create middleware code