add custom middleware to peer server, inspired by @creatorrr