Dynamic test environment sub domains and redirects with a nodejs app

I have a issue with dynamic test environment sub domains and redirects with a nodejs app and I was wondering if anyone has had any success with this. I have managed to use wildcards to whitelist the callbacks etc but wasn’t sure what the best approach would be to set the redirect_uri to handle the auth callback. Can anyone help?