refactor(server) middleware