I would say that the most important thing for you to do right now is to accept the fact that things are they way they are. Don't brood over what "could have been" or what "should have been", because neither of those things exist. They are just fantasies that will lead to even more frustration and misery.
It sounds as if he is a mature and responsible person. If that is the case, then I would assume you can still maintain a close friendship with him and a wonderful relationship with your child (ESPECIALLY the child, considering you are his mother). Just be sure to never, ever try to be "intimate" with him (the ex-husband) or do anything that could potentially cause a disruption within the current relationship between him and his wife.
If you love him, then it would only seem logical that you would feel happy and joyous for him if he is happy with his relationship, wouldn't it? You have to accept the fact that a long-lasting intimate relationship between you and him just wasn't meant to be. Also, do not brood over how you made a mistake. Mistakes, no matter how big or small, are ALWAYS great opportunities to learn and mature as a person, if you choose to take advantage of that opportunity. Think about your "mistake", contemplate and reflect on it, consider what lessons thre are to be learned from that mistake, and decide on how you are going to apply those lessons to your life in the future. Accept it and move on. Do not hold onto it and keep brooding over it or regretting it, because nothing positive can come from that.
The ego is rarely satisfied with what it currently "has". It always wants more. It will risk giving up whatever it currently has in order to find something better. It will fantasize about how much better things could be... no matter how good things are now, it will always want more. The ego likes to chase after fantasies, and this leads people to search for "greener grasses". Oftentimes they find that the grass actually ISN'T greener on the other side, but it's often too late to go back to the way things were. I guarantee you that you aren't experiencing anything that countless other people haven't also experienced.
You can't change what's been done. But you CAN choose how you wish to apply and express yourself in the future. Will you make the same "mistake" again in the future? You might. But it's less likely to happen now than it was before. You will think about things and spend more time contemplating on whether or not it's worth risking something good for fantasies of "greener grasses". Sometimes we have to lose something in order to realize how much it really meant to us. Know that your "mistake" and whatever frustration or suffering you are going through now as a result, were necessary for your own personal growth.
I STRONGLY advise that you work on building a strong relationship with your son. If he is not used to being very close to you, then don't expect instant results... it will take time, effort, and a lot of patience. But I guarantee you that if you are sincere, patient and persistent now, the long term results... a strong, close relationship between you and your son... will be just as fulfilling, if not moreso, than the "fantasy" relationship that "could have been" between you and your ex-husband.
There is absolutely no doubt in my mind that you will be able to work your way through this, and come out stronger, wiser and more mature as a result. There are many positive things just down the road... all you have to do is stop looking behind and start looking ahead.