ShreeshantXD commited on
Commit
90c0e10
·
1 Parent(s): 832f069

Add root landing page handler with links to dashboard and API endpoints

Browse files
Files changed (1) hide show
  1. main.go +53 -1
main.go CHANGED
@@ -138,6 +138,7 @@ func newServer() *Server {
138
 
139
  func (s *Server) routes() *http.ServeMux {
140
  mux := http.NewServeMux()
 
141
  mux.HandleFunc("/health", s.handleHealth)
142
  mux.HandleFunc("/ping", s.handlePing)
143
  mux.HandleFunc("/reset", s.handleReset)
@@ -153,6 +154,57 @@ func (s *Server) routes() *http.ServeMux {
153
  return mux
154
  }
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  // ── /health ──────────────────────────────────────────────────────────────────
157
 
158
  func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
@@ -413,7 +465,7 @@ func main() {
413
  srv.envMgr.Reset(env.ResetRequest{Seed: &seed, TaskID: 1, NumBuildings: 1})
414
 
415
  log.Printf("GridMind-RL environment server starting on :%s", port)
416
- log.Printf("Endpoints: GET /health /ping /state /replay /grade /tasks /metrics /dashboard | POST /reset /step")
417
 
418
  mux := withCORS(withLogging(srv.routes()))
419
  if err := http.ListenAndServe(":"+port, mux); err != nil {
 
138
 
139
  func (s *Server) routes() *http.ServeMux {
140
  mux := http.NewServeMux()
141
+ mux.HandleFunc("/", s.handleRoot)
142
  mux.HandleFunc("/health", s.handleHealth)
143
  mux.HandleFunc("/ping", s.handlePing)
144
  mux.HandleFunc("/reset", s.handleReset)
 
154
  return mux
155
  }
156
 
157
+ // ── / (Root) ────────────────────────────────────────────────────────────────
158
+
159
+ func (s *Server) handleRoot(w http.ResponseWriter, r *http.Request) {
160
+ if r.URL.Path != "/" {
161
+ http.NotFound(w, r)
162
+ return
163
+ }
164
+ w.Header().Set("Content-Type", "text/html")
165
+ html := `<!DOCTYPE html>
166
+ <html>
167
+ <head><title>GridMind-RL</title>
168
+ <style>
169
+ body { font-family: monospace; background: #0d1117; color: #e6edf3; padding: 40px; }
170
+ a { color: #58a6ff; text-decoration: none; }
171
+ a:hover { text-decoration: underline; }
172
+ .badge { background: #238636; padding: 4px 10px; border-radius: 4px; color: white; display: inline-block; }
173
+ ul { line-height: 1.8; }
174
+ pre { background: #0d1117; border: 1px solid #30363d; padding: 16px; border-radius: 6px; overflow-x: auto; }
175
+ </style>
176
+ </head>
177
+ <body>
178
+ <h1>⚡ GridMind-RL</h1>
179
+ <p><span class="badge">● RUNNING</span></p>
180
+ <p>Industrial building energy management RL environment — OpenEnv compliant.</p>
181
+ <h3>🔗 Quick Links</h3>
182
+ <ul>
183
+ <li><a href="/dashboard">→ Live Dashboard</a></li>
184
+ <li><a href="/health">→ API Health Check</a></li>
185
+ <li><a href="/tasks">→ Available Tasks</a></li>
186
+ <li><a href="/metrics">→ Prometheus Metrics</a></li>
187
+ </ul>
188
+ <h3>📡 API Endpoints</h3>
189
+ <pre>GET /health → health check
190
+ GET /ping → ping pong
191
+ GET /state → current environment state
192
+ GET /replay → episode replay data
193
+ GET /grade → episode grade score
194
+ GET /tasks → list of tasks
195
+ GET /metrics → prometheus metrics
196
+ POST /reset {task_id} → start new episode
197
+ POST /step {action} → take action</pre>
198
+ <h3>📚 Links</h3>
199
+ <ul>
200
+ <li><a href="https://github.com/shreeshantkhade/GridMind-RL">GitHub Repository</a></li>
201
+ <li><a href="https://openenv.org">OpenEnv Specification</a></li>
202
+ </ul>
203
+ </body>
204
+ </html>`
205
+ w.Write([]byte(html))
206
+ }
207
+
208
  // ── /health ──────────────────────────────────────────────────────────────────
209
 
210
  func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
 
465
  srv.envMgr.Reset(env.ResetRequest{Seed: &seed, TaskID: 1, NumBuildings: 1})
466
 
467
  log.Printf("GridMind-RL environment server starting on :%s", port)
468
+ log.Printf("Endpoints: GET / (landing) | GET /health /ping /state /replay /grade /tasks /metrics /dashboard | POST /reset /step")
469
 
470
  mux := withCORS(withLogging(srv.routes()))
471
  if err := http.ListenAndServe(":"+port, mux); err != nil {