Skip to content

Commit a2e4b7e

Browse files
Add middleware to handle all paths
1 parent 79e9fb8 commit a2e4b7e

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎orphan-domain-handler/main.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"gofr.dev/pkg/gofr"
5+
"net/http"
6+
"path/filepath"
57
)
68

79
const defaultStaticFilePath = `./static`
@@ -11,6 +13,18 @@ func main() {
1113

1214
staticFilePath := app.Config.GetOrDefault("STATIC_DIR_PATH", defaultStaticFilePath)
1315

16+
app.UseMiddleware(func(h http.Handler) http.Handler {
17+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
18+
w.WriteHeader(http.StatusNotFound)
19+
20+
filePath := filepath.Join(staticFilePath, "404.html")
21+
22+
http.ServeFile(w, r, filePath)
23+
24+
return
25+
})
26+
})
27+
1428
app.AddStaticFiles("/", staticFilePath)
1529

1630
app.Run()

0 commit comments

Comments
 (0)