move resolvePath outside middleware