Is there a way to do this without embedding url structure in the middleware?