Is there a way to have Javascript autodetect wether its server is local(127.0.0.1) or production(http://www.example.com) and set a variable accordingly?
For example in PHP is use this function to do reloads and it works local or production:
public static function reload()
{
$uri = 'http://';
$uri .= $_SERVER['HTTP_HOST'];
header('Location: '.$uri);
}
This way I won’t have to remember to edit my local_on variable when uploading my script from development to production.
There’s no built in ways like the one you mentioned.
You can, however, user a regex for detecting
/localhost/or127.0.0.1onwindow.location.hostThat’s the direct answer to your question. But you probably need to have a look at build tools for javascript or for your whole web development enterprises, e.g. minifyjs / remove console.log() etc.