change middleware type according to main module