mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
fix(web): fix panic on nil file info (#8907)
fix panic on nil file info
This commit is contained in:
parent
b21db878e8
commit
ee19f1749b
@ -72,17 +72,22 @@ func (provider *provider) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
// check whether a file exists or is a directory at the given path
|
// check whether a file exists or is a directory at the given path
|
||||||
fi, err := os.Stat(path)
|
fi, err := os.Stat(path)
|
||||||
if os.IsNotExist(err) || fi.IsDir() {
|
if err != nil {
|
||||||
// file does not exist or path is a directory, serve index.html
|
// if the file doesn't exist, serve index.html
|
||||||
http.ServeFile(rw, req, filepath.Join(provider.config.Directory, indexFileName))
|
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
|
||||||
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if fi.IsDir() {
|
||||||
// if we got an error (that wasn't that the file doesn't exist) stating the
|
// path is a directory, serve index.html
|
||||||
// file, return a 500 internal server error and stop
|
http.ServeFile(rw, req, filepath.Join(provider.config.Directory, indexFileName))
|
||||||
// TODO: Put down a crash html page here
|
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,10 @@ func TestServeHttpWithoutPrefix(t *testing.T) {
|
|||||||
name: "DoesNotExist",
|
name: "DoesNotExist",
|
||||||
path: "/does-not-exist",
|
path: "/does-not-exist",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Directory",
|
||||||
|
path: "/assets",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
@ -130,6 +134,11 @@ func TestServeHttpWithPrefix(t *testing.T) {
|
|||||||
path: "/web/does-not-exist",
|
path: "/web/does-not-exist",
|
||||||
found: true,
|
found: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Directory",
|
||||||
|
path: "/web/assets",
|
||||||
|
found: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "DoesNotExist",
|
name: "DoesNotExist",
|
||||||
path: "/does-not-exist",
|
path: "/does-not-exist",
|
||||||
|
|||||||
3
pkg/web/routerweb/testdata/assets/index.css
vendored
Normal file
3
pkg/web/routerweb/testdata/assets/index.css
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#root {
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user