func main() { logFile, err := os.OpenFile("logs/app.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) if err != nil { fmt.Println("Error accessing log file:", err) os.Exit(1) } r := mux.NewRouter() r.Handle("/", handlers.ProxyHeaders(handlers.LoggingHandler(logFile, repsheetHandler(http.HandlerFunc(LoginHandler))))) r.Handle("/admin", handlers.ProxyHeaders(handlers.LoggingHandler(logFile, repsheetHandler(http.HandlerFunc(AdminHandler))))) r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) http.Handle("/", r) err = http.ListenAndServe("localhost:8080", r) if err != nil { log.Fatal("Error starting server: ", err) } }
func runReplicaAPI(context *cli.Context) { router := http.Handler(replica.NewRouter()) router = handlers.LoggingHandler(os.Stdout, router) router = handlers.ProxyHeaders(router) listen := "0.0.0.0:80" logrus.Infof("Listening on %s", listen) err := http.ListenAndServe(listen, router) logrus.Fatalf("API returned with error: %v", err) }
func main() { parseFlags() ss := NewHTTPStaticServer(gcfg.Root) ss.Theme = gcfg.Theme ss.Title = gcfg.Title if gcfg.Upload { ss.EnableUpload() } if gcfg.PlistProxy != nil { gcfg.PlistProxy.Scheme = "https" ss.PlistProxy = gcfg.PlistProxy.String() } var hdlr http.Handler = ss hdlr = accesslog.NewLoggingHandler(hdlr, l) // HTTP Basic Authentication userpass := strings.SplitN(gcfg.HttpAuth, ":", 2) if len(userpass) == 2 { user, pass := userpass[0], userpass[1] hdlr = httpauth.SimpleBasicAuth(user, pass)(hdlr) } // CORS if gcfg.Cors { hdlr = handlers.CORS()(hdlr) } if gcfg.XHeaders { hdlr = handlers.ProxyHeaders(hdlr) } http.Handle("/", hdlr) http.HandleFunc("/-/sysinfo", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") data, _ := json.Marshal(map[string]interface{}{ "version": VERSION, }) w.Write(data) }) log.Printf("Listening on addr: %s\n", strconv.Quote(gcfg.Addr)) var err error if gcfg.Key != "" && gcfg.Cert != "" { err = http.ListenAndServeTLS(gcfg.Addr, gcfg.Cert, gcfg.Key, nil) } else { err = http.ListenAndServe(gcfg.Addr, nil) } log.Fatal(err) }
func main() { log.Infof("Starting Helphone API service on port %s", port) router := service.NewRouter() h := service.MuxWrapper{ IsReady: false, Router: router, } go manager.Init() handler := handlers.CompressHandler(handlers.ProxyHeaders(cors.Default().Handler(h.Router))) log.Fatal(http.ListenAndServe(":"+port, handler)) }
func (d *Device) start() error { listen := "localhost:9414" server := NewServer(d) router := http.Handler(NewRouter(server)) router = handlers.LoggingHandler(os.Stdout, router) router = handlers.ProxyHeaders(router) log.Infof("Rest Frontend listening on %s", listen) go func() { http.ListenAndServe(listen, router) }() return nil }
func main() { flag.Parse() // Logging setup level, err := log.ParseLevel(*loglevel) if err != nil { log.Fatal(err) } log.SetLevel(level) h := hub.New() go h.Run() router := mux.NewRouter() router.NotFoundHandler = misakaNotFoundHandler{} router.Handle("/rnp", user.Handler(h)) logHandler := handlers.CombinedLoggingHandler(os.Stderr, router) proxyHeaderHandler := handlers.ProxyHeaders(logHandler) http.Handle("/", proxyHeaderHandler) var l net.Listener var listenFields log.Fields if strings.ContainsRune(*bind, '/') { listenFields = log.Fields{"bind": *bind, "listener": "unix"} a, err := net.ResolveUnixAddr("unix", *bind) if err != nil { log.WithFields(listenFields).Fatal(err) } l, err = net.ListenUnix("unix", a) if err != nil { log.WithFields(listenFields).Fatal(err) } defer func() { log.WithFields(listenFields).Debug("Cleaning up socket") err = os.Remove(*bind) if err != nil { log.WithFields(listenFields).Fatalf( "Failed to unlink socket: %s", err) } }() err = os.Chmod(*bind, os.ModePerm) if err != nil { log.WithFields(listenFields).Fatalf("Could not set socket permissions: %s", err) } } else { listenFields = log.Fields{"bind": *bind, "listener": "tcp"} a, err := net.ResolveTCPAddr("tcp", *bind) if err != nil { log.WithFields(listenFields).Fatal(err) } l, err = net.ListenTCP("tcp", a) if err != nil { log.WithFields(listenFields).Fatal(err) } } go func() { if err := http.Serve(l, nil); err != nil { log.Fatal(err) } }() log.WithFields(listenFields).Info("Radio Noise Project listening") sigChan := make(chan os.Signal) signal.Notify(sigChan, syscall.SIGINT, syscall.SIGQUIT) sig := <-sigChan log.WithFields(log.Fields{"signal": sig}).Info("Exiting due to signal") h.Done() }