<commit_before>package cmd

import (
	"crypto/tls"
	"fmt"
	"net/http"

	"github.com/getfider/fider/app/pkg/env"
)

//RunPing checks if Fider Server is running and is healthy
//Returns an exitcode, 0 for OK and 1 for ERROR
func RunPing() int {
	protocol := "http://"
	if env.Config.TLS.Certificate != "" || env.Config.TLS.Automatic {
		http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
			InsecureSkipVerify: true,
		}
		protocol = "https://"
	}

	resp, err := http.Get(protocol + "localhost:3000/_health")
	if err != nil {
		fmt.Printf("Request failed with: %s\n", err)
		return 1
	}

	defer resp.Body.Close()
	if resp.StatusCode >= 400 {
		fmt.Printf("Request failed with status code: %d\n", resp.StatusCode)
		return 1
	}

	return 0
}<commit_msg>fix: Healthcheck errors if Host Domain set (#1048)<commit_after>package cmd

import (
	"crypto/tls"
	"fmt"
	"net/http"

	"github.com/getfider/fider/app/pkg/env"
)

//RunPing checks if Fider Server is running and is healthy
//Returns an exitcode, 0 for OK and 1 for ERROR
func RunPing() int {

	client := &http.Client{}

	host := "localhost:" + env.Config.Port
	protocol := "http://"
	if env.Config.TLS.Certificate != "" || env.Config.TLS.Automatic {
		http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{
			InsecureSkipVerify: true,
		}
		protocol = "https://"
	}

	req, err := http.NewRequest("GET", protocol+host+"/_health", nil)
	if err != nil {
		fmt.Printf("Setting up request failed with: %s", err)
		return 1
	}

	// Set Host if HostDomain is set
	if env.IsSingleHostMode() && len(env.Config.HostDomain) > 0 {
		req.Host = env.Config.HostDomain
	}

	resp, err := client.Do(req)
	if err != nil {
		fmt.Printf("Request failed with: %s\n", err)
		return 1
	}

	defer resp.Body.Close()
	if resp.StatusCode >= 400 {
		fmt.Printf("Request failed with status code: %d\n", resp.StatusCode)
		return 1
	}

	return 0
}
{'fraction_non_alphanumeric': 0.15028901734104047, 'fraction_numerical': 0.013662637940094587, 'mean_word_length': 3.5990338164251208, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4176701', 'n_tokens_mistral': 725, 'n_tokens_neox': 675, 'n_words': 182}