fix middleware ordering in production settings