exporting middleware and fixing reverse endpoint