Jammming step 99 changing redirect to http://localhost:3000/callback/ solves the redirect error BUT WHY?

I ran into a similar problem as many others. When using surge to deploy the Jammming app and following the directions: change the redirect URI on both the Spotify dashboard and in your Spotify.js I got an authentication error because the URI was wrong.

Reading several topics about it, the solution is to change whatever.surge.sh to localhost:3000/callback/ in both locations. It works. But nobody explains WHY it works.

Can someone please explain this to me?

For reference:

let accessToken;
const clientID = '7432ea43240b4ad1bf6c309a28f2723f';
//const redirectURI = "mysuperappJammming.surge.sh"; <-- THIS DOES NOT WORK
// I tried it with http:// and https:// as well

const redirectURI = "http://localhost:3000/callback/"; // <-- THIS DOES WORK

const Spotify = {      
//rest of the module

have you deployed the site before changing the redirectURI to the .surge.sh location?

If you have you need to change your files to the surge.sh redirectURI and then redeploy. It seems as though the localhost redirectURI is the one published (you can check in dev tools elements)

And check which redirectURI you have authorised in the Spotify for developers app profile. You can add multiple