--- /dev/null
+package main
+
+import (
+ "flag"
+ "fmt"
+ "log"
+ "net/http"
+ "os"
+ "strconv"
+
+ "creative-path-pep/pkg/constants"
+ "creative-path-pep/pkg/handlers"
+ "creative-path-pep/pkg/logger"
+
+ "github.com/gorilla/mux"
+)
+
+func main() {
+ paramDeploy := flag.Bool(
+ "d", false, "A flag specifying the deploy mode of the server.")
+ paramPort := flag.Int(
+ "p", 8000, "The port the server should be deployed on.")
+ _ = flag.String(
+ "base", "localhost:8000", "Where websockets should connect.")
+ cert := flag.String("c", "", "State the certificate location")
+ secret := flag.String("k", "", "State the private key location")
+ flag.Parse()
+
+ logFile, err := os.OpenFile(constants.MainLogFile, os.O_APPEND | os.O_RDWR, 0664)
+ if err != nil {
+ fmt.Println("[ERROR] Failed to open main log file.")
+ panic("Could not open log file.")
+ }
+ defer logFile.Close()
+
+ logger.InfoLog = log.New(logFile, "[INFO] ", logger.LoggerFlags)
+ logger.RequestLog = log.New(logFile, "[REQUEST] ", logger.LoggerFlags)
+ logger.ErrorLog = log.New(logFile, "[ERROR] ", logger.LoggerFlags)
+
+ cssDir := http.Dir("static/css")
+ imgDir := http.Dir("static/images")
+ jsDir := http.Dir("static/js")
+ fontsDir := http.Dir("static/fonts")
+
+ _ = "none"
+ if *paramDeploy {
+ _ = "ssl"
+ }
+
+ router := mux.NewRouter()
+ router.HandleFunc("/", handlers.HandleIndex)
+
+ http.Handle("/", router)
+ http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(cssDir)))
+ http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(imgDir)))
+ http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(jsDir)))
+ http.Handle("/fonts/", http.StripPrefix("/fonts/", http.FileServer(fontsDir)))
+
+ listenPort := ":" + strconv.Itoa(*paramPort)
+ if *paramDeploy {
+ fmt.Println("Began listening (SSL) on port:", listenPort);
+ err = http.ListenAndServeTLS(listenPort, *cert, *secret, nil)
+
+ } else {
+ fmt.Println("Began listening on port:", listenPort);
+ err = http.ListenAndServe(listenPort, nil)
+ }
+
+ if err != nil {
+ logger.ErrorLog.Fatalf("Listen and serve failed with:", err)
+ }
+}