use middleware instead of direct app reference