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
|
||||
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))
|
||||
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
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// 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)
|
||||
if fi.IsDir() {
|
||||
// path is a directory, serve index.html
|
||||
http.ServeFile(rw, req, filepath.Join(provider.config.Directory, indexFileName))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -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",
|
||||
|
||||
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