magic middleware