Example #1
0
func getNatsOptions(chanLen int) *nats.Options {
	opts := nats.DefaultOptions
	opts.SubChanLen = chanLen
	opts.AsyncErrorCB = asyncErrorHandler
	opts.Servers = config.C().Nats
	for i, s := range opts.Servers {
		opts.Servers[i] = strings.Trim(s, " ")
	}
	opts.Secure = config.C().NatsUseTls
	return &opts
}
Example #2
0
func main() {
	port := config.C().HttpServerPort
	connTimeout := config.C().ConnectionTimeout
	logtype := config.C().LogType
	if logtype == "" {
		logtype = "stdout"
	}
	setupLogger(logtype)
	startGcLoop(1000)
	usetls := config.C().HttpServerUseTls
	c := &ax.Config{ConnectionTimeout: connTimeout, UseTls: usetls}
	r := ax.Setup(c)
	setupRoutes(r)
	setMessageHandlers()
	start(r, port, usetls)
}
Example #3
0
func indexFileHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	if config.C().HttpServerUseTls {
		w.Header().Set("Strict-Transport-Security",
			"max-age=31536000; includeSubDomains")
	}
	http.ServeFile(w, r, "./www/index.html")
}
Example #4
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())
}
Example #5
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())
	}
}
Example #6
0
func redirHandler(w http.ResponseWriter, req *http.Request) {
	http.Redirect(w, req, config.C().RedirTo+req.RequestURI,
		http.StatusMovedPermanently)
}
Example #7
0
func Init() {
	client.Addr = config.C().RedisAddr
	client.Db = config.C().RedisDb
	client.Password = config.C().RedisPassword
}