Refactor cors middleware into separate module