The optimal constant in Hardy-type inequalities