move from middleware to server