moving relay logic to middleware
setup relay middleware