<commit_before>package main

import (
	"flag"
	"fmt"
	"log"
	"net/url"
	"os"
	"strconv"

	"github.com/koding/kite/config"
	"github.com/koding/kite/reverseproxy"
)

var (
	flagCertFile    = flag.String("cert", "", "Cert file to be used for HTTPS")
	flagKeyFile     = flag.String("key", "", "Key file to be used for HTTPS")
	flagIp          = flag.String("ip", "0.0.0.0", "Listening IP")
	flagPort        = flag.Int("port", 3999, "Server port")
	flagPublicHost  = flag.String("host", "127.0.0.1:3999", "Public host of Proxy.")
	flagRegion      = flag.String("region", "", "Change region")
	flagEnvironment = flag.String("env", "development", "Change development")
	flagVersion     = flag.Bool("version", false, "Show version and exit")
)

func main() {
	flag.Parse()

	if *flagVersion {
		fmt.Println(reverseproxy.Version)
		os.Exit(0)
	}

	if *flagRegion == "" || *flagEnvironment == "" {
		log.Fatal("Please specify envrionment via -env and region via -region. Aborting.")
	}

	scheme := "ws"
	if *flagCertFile != "" && *flagKeyFile != "" {
		scheme = "wss"
	}

	conf := config.MustGet()
	conf.IP = *flagIp
	conf.Port = *flagPort
	conf.Region = *flagRegion
	conf.Environment = *flagEnvironment

	r := reverseproxy.New(conf)
	r.PublicHost = *flagPublicHost
	r.Scheme = scheme

	registerURL := &url.URL{
		Scheme: scheme,
		Host:   r.PublicHost + ":" + strconv.Itoa(*flagPort),
		Path:   "/kite",
	}

	r.Kite.Log.Info("Registering with register url %s", registerURL)
	if err := r.Kite.RegisterForever(registerURL); err != nil {
		r.Kite.Log.Fatal("Registering to Kontrol: %s", err)
	}

	if *flagCertFile == "" || *flagKeyFile == "" {
		log.Println("No cert/key files are defined. Running proxy unsecure.")
		err := r.ListenAndServe()
		if err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
	} else {
		err := r.ListenAndServeTLS(*flagCertFile, *flagKeyFile)
		if err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
	}
}
<commit_msg>reverseproxy/main: we now use sockjs, no more ws/wss<commit_after>package main

import (
	"flag"
	"fmt"
	"log"
	"net/url"
	"os"
	"strconv"

	"github.com/koding/kite/config"
	"github.com/koding/kite/reverseproxy"
)

var (
	flagCertFile    = flag.String("cert", "", "Cert file to be used for HTTPS")
	flagKeyFile     = flag.String("key", "", "Key file to be used for HTTPS")
	flagIp          = flag.String("ip", "0.0.0.0", "Listening IP")
	flagPort        = flag.Int("port", 3999, "Server port")
	flagPublicHost  = flag.String("host", "127.0.0.1:3999", "Public host of Proxy.")
	flagRegion      = flag.String("region", "", "Change region")
	flagEnvironment = flag.String("env", "development", "Change development")
	flagVersion     = flag.Bool("version", false, "Show version and exit")
)

func main() {
	flag.Parse()

	if *flagVersion {
		fmt.Println(reverseproxy.Version)
		os.Exit(0)
	}

	if *flagRegion == "" || *flagEnvironment == "" {
		log.Fatal("Please specify envrionment via -env and region via -region. Aborting.")
	}

	scheme := "http"
	if *flagCertFile != "" && *flagKeyFile != "" {
		scheme = "https"
	}

	conf := config.MustGet()
	conf.IP = *flagIp
	conf.Port = *flagPort
	conf.Region = *flagRegion
	conf.Environment = *flagEnvironment

	r := reverseproxy.New(conf)
	r.PublicHost = *flagPublicHost
	r.Scheme = scheme

	registerURL := &url.URL{
		Scheme: scheme,
		Host:   r.PublicHost + ":" + strconv.Itoa(*flagPort),
		Path:   "/kite",
	}

	r.Kite.Log.Info("Registering with register url %s", registerURL)
	if err := r.Kite.RegisterForever(registerURL); err != nil {
		r.Kite.Log.Fatal("Registering to Kontrol: %s", err)
	}

	if *flagCertFile == "" || *flagKeyFile == "" {
		log.Println("No cert/key files are defined. Running proxy unsecure.")
		err := r.ListenAndServe()
		if err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
	} else {
		err := r.ListenAndServeTLS(*flagCertFile, *flagKeyFile)
		if err != nil {
			log.Fatal("ListenAndServe: ", err)
		}
	}
}

{'fraction_non_alphanumeric': 0.17155986724534084, 'fraction_numerical': 0.00970130201684963, 'mean_word_length': 3.664285714285714, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '1987921', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1427, 'n_words': 323}