Refactor Connect middleware to use framework support.