package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

var FailureListen string
var FailureWebpage []byte

func FailureServer() {
	FailureListen = ":8080"
	if ConfigData.Frontend.Enable {
		if ConfigData.Frontend.ListenAddr != "" {
			FailureListen = ConfigData.Frontend.ListenAddr
		}
	}
	var err error
	FailureWebpage, err = ioutil.ReadFile("/rel/failure.html")
	if err != nil {
		fmt.Println("Failed Load Failure Webpage.")
		FailureWebpage = []byte("<h1>zDWSI Failure</h1>")
	}
	http.HandleFunc("/", handleFailurePage)
	http.ListenAndServe(FailureListen, nil)
}
func handleFailurePage(writer http.ResponseWriter, request *http.Request) {
	_ = request
	writer.WriteHeader(502)
	writer.Write(FailureWebpage)
}
