Serve the index page for an empty URL path instead of panicking (closes #149)
check / check (push) Waiting to run
check / check (push) Waiting to run
setupSPA took the file name from request.URL.Path[1:], which panics
when the path is empty, as it is for an absolute-form request line
with no path ("GET http://host HTTP/1.1"). It now trims a leading "/"
instead; an empty name fails to read, so the request gets the index
page, as "/" already does.
The new test in internal/server sends such a request and expects 200
and the index page. export_test.go gives it a Server whose router has
only the web client route.
Model: opus-5-5
This commit was merged in pull request #165.
This commit is contained in:
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/neoirc/web"
|
||||
@@ -137,8 +138,10 @@ func (srv *Server) setupSPA() {
|
||||
return
|
||||
}
|
||||
|
||||
// The path is empty, not "/", for a request line such
|
||||
// as "GET http://host HTTP/1.1".
|
||||
fileData, readErr := readFS.ReadFile(
|
||||
request.URL.Path[1:],
|
||||
strings.TrimPrefix(request.URL.Path, "/"),
|
||||
)
|
||||
if readErr != nil || len(fileData) == 0 {
|
||||
indexHTML, indexErr := readFS.ReadFile(
|
||||
|
||||
Reference in New Issue
Block a user