#488 Adding middleware for checking if request is using https and refactoring https checking in api