Skip to content

Commit 1716e13

Browse files
authored
lsp/webserver: Add links to the index page (#1914)
In case a user ends up here not knowing what the page is. Signed-off-by: Charlie Egan <charlie_egan@apple.com>
1 parent 02a9dc8 commit 1716e13

3 files changed

Lines changed: 43 additions & 17 deletions

File tree

internal/web/index.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Regal Language Server</title>
7+
<link rel="stylesheet" href="/style.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<h1>Regal Language Server</h1>
12+
<p>
13+
<a href="https://www.openpolicyagent.org/projects/regal">Regal Website</a>
14+
- Project documentation
15+
</p>
16+
<p>
17+
<a href="https://www.openpolicyagent.org/projects/regal/editor-support">Editor Support</a>
18+
- Instructions to configure your editor for Regal
19+
</p>
20+
<p>
21+
Start server with <code>REGAL_DEBUG</code> or <code>REGAL_DEBUG_PPROF</code> set to enable pprof endpoints
22+
</p>
23+
</div>
24+
</body>
25+
</html>

internal/web/server.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package web
22

33
import (
44
"context"
5+
"embed"
56
"fmt"
67
"net"
78
"net/http"
@@ -14,6 +15,9 @@ import (
1415
"github.com/open-policy-agent/regal/internal/util"
1516
)
1617

18+
//go:embed index.html style.css
19+
var content embed.FS
20+
1721
type Server struct {
1822
log *log.Logger
1923
baseURL string
@@ -54,23 +58,7 @@ func (s *Server) Start(context.Context) {
5458
}
5559

5660
// root handler for those looking for what the server is
57-
mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
58-
body := `
59-
<h1>Regal Language Server</h1>
60-
<ul>`
61-
62-
if pprofEndpoints {
63-
body += `<li><a href="/debug/pprof/">pprof</a></li>
64-
<li><a href="/debug/statsviz">statsviz</a></li>
65-
</ul>`
66-
} else {
67-
body += `Start server with REGAL_DEBUG or REGAL_DEBUG_PPROF set to enable pprof endpoints`
68-
}
69-
70-
if _, err := w.Write([]byte(body)); err != nil {
71-
s.log.Message("failed to write response: %v", err)
72-
}
73-
})
61+
mux.Handle("/", http.FileServerFS(content))
7462

7563
freePort, err := util.FreePort(5052, 5053, 5054)
7664
if err != nil {

internal/web/style.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
body {
2+
font-family: system-ui, sans-serif;
3+
line-height: 1.6;
4+
color: #333;
5+
}
6+
.container {
7+
max-width: 50rem;
8+
margin: 0 auto;
9+
padding: 1.25rem;
10+
}
11+
a {
12+
color: #0066cc;
13+
}

0 commit comments

Comments
 (0)