@@ -44,6 +44,36 @@ func TestStatic_useCaseForApiAndSPAs(t *testing.T) {
4444
4545}
4646
47+ func TestStaticHTML5PreservesMatchedHandlerNotFound (t * testing.T ) {
48+ e := echo .New ()
49+ e .Use (StaticWithConfig (StaticConfig {
50+ Root : "testdata/dist/public" ,
51+ HTML5 : true ,
52+ }))
53+ e .GET ("/api/users/:id" , func (c * echo.Context ) error {
54+ return echo .NewHTTPError (http .StatusNotFound , "user not found" )
55+ })
56+
57+ req := httptest .NewRequest (http .MethodGet , "/api/users/42" , nil )
58+ rec := httptest .NewRecorder ()
59+ e .ServeHTTP (rec , req )
60+
61+ assert .Equal (t , http .StatusNotFound , rec .Code )
62+ assert .JSONEq (t , `{"message":"user not found"}` , rec .Body .String ())
63+
64+ group := echo .New ()
65+ group .Group ("/app" , StaticWithConfig (StaticConfig {
66+ Root : "testdata/dist/public" ,
67+ HTML5 : true ,
68+ }))
69+ req = httptest .NewRequest (http .MethodGet , "/app/dashboard" , nil )
70+ rec = httptest .NewRecorder ()
71+ group .ServeHTTP (rec , req )
72+
73+ assert .Equal (t , http .StatusOK , rec .Code )
74+ assert .Contains (t , rec .Body .String (), "<h1>Hello from index</h1>\n " )
75+ }
76+
4777func TestStatic (t * testing.T ) {
4878 var testCases = []struct {
4979 name string
0 commit comments