@@ -63,18 +63,20 @@ func (r *router) Run(ctx context.Context) error {
63
63
// HTTP ROUTER
64
64
65
65
// Register a function to handle a URL path
66
- func (r * router ) HandleFunc (ctx context.Context , prefix string , fn http.HandlerFunc ) {
66
+ func (r * router ) HandleFunc (parent context.Context , prefix string , fn http.HandlerFunc ) {
67
67
// Wrap the function with middleware
68
68
for _ , middleware := range r .middleware {
69
69
fn = middleware .HandleFunc (fn )
70
70
}
71
71
72
72
// Apply middleware, set context
73
- ref .Log (ctx ).Debug (ctx , "Register route: " , types .JoinPath (r .prefix , prefix ))
73
+ ref .Log (parent ).Debug (parent , "Register route: " , types .JoinPath (r .prefix , prefix ))
74
74
r .ServeMux .HandleFunc (types .JoinPath (r .prefix , prefix ), func (w http.ResponseWriter , r * http.Request ) {
75
- r = r .WithContext (ref .WithLog (r .Context (), ref .Log (ctx )))
76
- // TODO: Add Log into the r context, but don't replace the original
77
- fn (w , r )
75
+ // Add provider to context
76
+ ctx := ref .WithProvider (r .Context (), ref .Provider (parent ))
77
+
78
+ // Serve the request
79
+ fn (w , r .WithContext (ctx ))
78
80
})
79
81
}
80
82
@@ -84,7 +86,7 @@ func (r *router) Origin() string {
84
86
}
85
87
86
88
// Register serving of static files from a filesystem
87
- func (r * router ) HandleFS (ctx context.Context , prefix string , fs fs.FS ) {
89
+ func (r * router ) HandleFS (parent context.Context , prefix string , fs fs.FS ) {
88
90
// Create the file server
89
91
fn := http .StripPrefix (types .JoinPath (r .prefix , prefix ), http .FileServer (http .FS (fs ))).ServeHTTP
90
92
@@ -94,12 +96,12 @@ func (r *router) HandleFS(ctx context.Context, prefix string, fs fs.FS) {
94
96
}
95
97
96
98
// Apply middleware
97
- ref .Log (ctx ).Debug (ctx , "Register route : " , types .JoinPath (r .prefix , prefix ))
99
+ ref .Log (parent ).Debug (parent , "Register static : " , types .JoinPath (r .prefix , prefix ))
98
100
r .ServeMux .HandleFunc (types .JoinPath (r .prefix , prefix ), func (w http.ResponseWriter , req * http.Request ) {
99
101
// Set CORS headers
100
102
httpresponse .Cors (w , req , r .origin , http .MethodGet )
101
103
102
104
// Call the file server
103
- fn (w , req .WithContext (ref .WithLog ( ctx , ref .Log ( ctx ))))
105
+ fn (w , req .WithContext (ref .WithProvider ( parent , ref .Provider ( parent ))))
104
106
})
105
107
}
0 commit comments