mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2025-09-02 02:44:36 +00:00
Add checks for network connectivity
This commit is contained in:
23
src/nvm.go
23
src/nvm.go
@@ -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
|
||||||
|
@@ -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 {
|
||||||
|
Reference in New Issue
Block a user