Move dir middleware to lib