Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(web): fix panic on nil file info (#8907)

Vibhu Pandeyee19f1749bda
diff --git a/pkg/web/routerweb/provider.go b/pkg/web/routerweb/provider.go
index ccc632652f..9ec07da85b 100644
--- a/pkg/web/routerweb/provider.go
+++ b/pkg/web/routerweb/provider.go
@@ -72,20 +72,25 @@ func (provider *provider) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// check whether a file exists or is a directory at the given path
fi, err := os.Stat(path)
- if os.IsNotExist(err) || fi.IsDir() {
- // file does not exist or path is a directory, serve index.html
- http.ServeFile(rw, req, filepath.Join(provider.config.Directory, indexFileName))
- return
- }
-
if err != nil {
+ // if the file doesn't exist, serve index.html
+ if os.IsNotExist(err) {
+ http.ServeFile(rw, req, filepath.Join(provider.config.Directory, indexFileName))
+ return
+ }
+
// if we got an error (that wasn't that the file doesn't exist) stating the
// file, return a 500 internal server error and stop
- // TODO: Put down a crash html page here
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
+ if fi.IsDir() {
+ // path is a directory, serve index.html
+ http.ServeFile(rw, req, filepath.Join(provider.config.Directory, indexFileName))
+ return
+ }
+
// otherwise, use http.FileServer to serve the static file
http.FileServer(http.Dir(provider.config.Directory)).ServeHTTP(rw, req)
}
diff --git a/pkg/web/routerweb/provider_test.go b/pkg/web/routerweb/provider_test.go
index 22c82f9b7a..96db1edb37 100644
--- a/pkg/web/routerweb/provider_test.go
+++ b/pkg/web/routerweb/provider_test.go
@@ -61,6 +61,10 @@ func TestServeHttpWithoutPrefix(t *testing.T) {
name: "DoesNotExist",
path: "/does-not-exist",
},
+ {
+ name: "Directory",
+ path: "/assets",
+ },
}
for _, tc := range testCases {
@@ -130,6 +134,11 @@ func TestServeHttpWithPrefix(t *testing.T) {
path: "/web/does-not-exist",
found: true,
},
+ {
+ name: "Directory",
+ path: "/web/assets",
+ found: true,
+ },
{
name: "DoesNotExist",
path: "/does-not-exist",
diff --git a/pkg/web/routerweb/testdata/assets/index.css b/pkg/web/routerweb/testdata/assets/index.css
new file mode 100644
index 0000000000..f93ad5f421
--- /dev/null
+++ b/pkg/web/routerweb/testdata/assets/index.css
@@ -0,0 +1,3 @@
+#root {
+ background-color: red;
+}
\ No newline at end of file