ticket:3 rewrite middleware