summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go81
1 files changed, 0 insertions, 81 deletions
diff --git a/main.go b/main.go
deleted file mode 100644
index 80a3583..0000000
--- a/main.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package main
-
-import (
- "encoding/json"
- "flag"
- "fmt"
- "log"
- "net/http"
- "os"
-)
-
-// Configuration for the server
-type Config struct {
- Debug bool
- Port int
-}
-
-// Environment variables to pass to frontend
-type EnvVars struct {
- Thing int `json:"thing"`
- // Add more environment variables as needed
-}
-
-// Get environment variables to pass to frontend
-func getEnvVars() EnvVars {
- return EnvVars{
- Thing: 1,
- // Add more variables as needed
- }
-}
-
-func main() {
- // Parse command line flags
- config := Config{}
- flag.IntVar(&config.Port, "port", 5000, "Port to run the server on")
- flag.BoolVar(&config.Debug, "debug", true, "Enable debug mode")
- flag.Parse()
-
- // Override port from environment variable if set
- if portStr := os.Getenv("PORT"); portStr != "" {
- var err error
- config.Port, err = fmt.Sscanf(portStr, "%d", &config.Port)
- if err != nil {
- log.Printf("Warning: Invalid PORT environment variable: %s. Using default port %d", portStr, config.Port)
- }
- }
-
- // Create a file server for static files
- fs := http.FileServer(http.Dir("."))
-
- // Set up routes
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
- // If the request is for the root path, serve index.html
- if r.URL.Path == "/" {
- http.ServeFile(w, r, "index.html")
- return
- }
- // Otherwise, use the file server to serve static files
- fs.ServeHTTP(w, r)
- })
-
- // API routes
- http.HandleFunc("/api/env", func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(getEnvVars())
- })
-
- http.HandleFunc("/api/health", func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
- })
-
- // Error handlers are handled by default Go error handling
-
- // Start the server
- addr := fmt.Sprintf(":%d", config.Port)
- log.Printf("Starting server at http://localhost%s", addr)
- if err := http.ListenAndServe(addr, nil); err != nil {
- log.Fatalf("Server error: %v", err)
- }
-}