Add checks for network connectivity

This commit is contained in:
Corey Butler
2023-02-13 19:41:21 -06:00
parent 6e2c8da2dc
commit 9366b98d10
2 changed files with 44 additions and 0 deletions

View File

@@ -928,10 +928,33 @@ func checkLocalEnvironment() {
fmt.Printf("\nWindows Developer Mode: %v\n", devmode) fmt.Printf("\nWindows Developer Mode: %v\n", devmode)
} }
fmt.Printf("\nInformation\n-----------\nPath: %v\nVersion: %v\nNVM_HOME: %v\nNVM_SYMLINK: %v\n", os.Args[0], NvmVersion, home, symlink)
if !nvmsymlinkfound { if !nvmsymlinkfound {
problems = append(problems, "The NVM4W symlink ("+env.symlink+") was not found in the PATH environment variable.") problems = append(problems, "The NVM4W symlink ("+env.symlink+") was not found in the PATH environment variable.")
} }
nodelist := web.Ping(web.GetFullNodeUrl("index.json"))
if !nodelist {
if len(env.node_mirror) > 0 && env.node_mirror != "none" {
problems = append(problems, "Connection to "+env.node_mirror+" (mirror) cannot be established. Check the mirror server to assure it is online.")
} else {
if len(env.proxy) > 0 {
problems = append(problems, "Connection to nodejs.org cannot be established. Check your proxy ("+env.proxy+") and your physical internet connection.")
} else {
problems = append(problems, "Connection to nodejs.org cannot be established. Check your internet connection.")
}
}
}
if len(env.npm_mirror) > 0 {
fmt.Println("If you are experiencing npm problems, check the npm mirror (" + env.npm_mirror + ") to assure it is online and accessible.")
}
if _, err := os.Stat(env.settings); err != nil {
problems = append(problems, "Cannot find "+env.settings)
}
if len(problems) == 0 { if len(problems) == 0 {
fmt.Println("\nNo problems detected.") fmt.Println("\nNo problems detected.")
return return

View File

@@ -66,6 +66,27 @@ func GetFullNpmUrl(path string) string {
return npmBaseAddress + path return npmBaseAddress + path
} }
func Ping(url string) bool {
req, err := http.NewRequest("HEAD", url, nil)
if err != nil {
fmt.Println(err)
return false
}
req.Header.Set("User-Agent", "NVM for Windows")
response, err := client.Do(req)
if err != nil {
return false
}
if response.StatusCode == 200 {
return true
}
return false
}
func Download(url string, target string, version string) bool { func Download(url string, target string, version string) bool {
output, err := os.Create(target) output, err := os.Create(target)
if err != nil { if err != nil {