Exemplo n.º 1
0
func redir() {
	port := config.C().RedirFromPort
	if port == 0 {
		port = 80
	}
	log.Printf("Serving %d for redirection\n", port)
	addr := fmt.Sprintf(":%d", port)
	r := mux.NewRouter()
	r.HandleFunc("/", redirHandler).Methods("GET")
	r.HandleFunc("/{tunnel_name}", redirHandler).Methods("GET")
	srv := endless.NewServer(addr, r)
	log.Println(srv.ListenAndServe())
}
Exemplo n.º 2
0
func start(r *ax.Router, port int, usetls bool) {
	log.Printf("Serving %d, use TLS: %v\n", port, usetls)
	addr := fmt.Sprintf(":%d", port)
	srv := endless.NewServer(addr, nil)
	srv.SignalHooks[endless.PRE_SIGNAL][syscall.SIGHUP] = append(
		srv.SignalHooks[endless.PRE_SIGNAL][syscall.SIGHUP],
		preSigHup)
	srv.SignalHooks[endless.PRE_SIGNAL][syscall.SIGINT] = append(
		srv.SignalHooks[endless.PRE_SIGNAL][syscall.SIGINT],
		preSigInt)
	endless.DefaultHammerTime = -1 // disable hammering the server
	if usetls {
		certfname := path.Join(tlsFilesPath, tlsCertFileName)
		keyfname := path.Join(tlsFilesPath, tlsKeyFileName)
		if config.C().RedirTo != "" {
			go redir()
		}
		log.Println(srv.ListenAndServeTLS(certfname, keyfname))
	} else {
		log.Println(srv.ListenAndServe())
	}
}