@@ -239,38 +239,40 @@ async fn handle_worker_request(
239239 // Handle resolution result
240240 let worker = match resolution {
241241 Some ( res) => {
242+ use openworkers_runner:: BackendType ;
243+ use openworkers_runner:: store:: get_worker_with_bindings;
244+
242245 // Project routing: check backend type
243246 if res. project_id . is_some ( ) {
244247 // Record backend type for telemetry
245248 span. record ( "backend_type" , tracing:: field:: display ( & res. backend_type ) ) ;
246249
247250 match res. backend_type {
248- openworkers_runner :: BackendType :: Worker => {
251+ BackendType :: Worker => {
249252 if let Some ( worker_id) = res. worker_id {
250- let worker = openworkers_runner:: store:: get_worker_with_bindings (
251- conn,
252- WorkerIdentifier :: Id ( worker_id) ,
253- )
254- . await ;
253+ let worker =
254+ get_worker_with_bindings ( conn, WorkerIdentifier :: Id ( worker_id) )
255+ . await ;
255256
256257 match worker {
257258 Some ( w) => w,
258259 None => {
259260 return Ok ( error_response_with_span (
260261 & span,
261- 404 ,
262- "Worker not found" ,
262+ 500 ,
263+ "Route has worker backend but worker not found" ,
263264 ) ) ;
264265 }
265266 }
266267 } else {
267- return Ok ( error_response (
268+ return Ok ( error_response_with_span (
269+ & span,
268270 500 ,
269271 "Route has worker backend but no worker_id" ,
270272 ) ) ;
271273 }
272274 }
273- openworkers_runner :: BackendType :: Storage => {
275+ BackendType :: Storage => {
274276 use openworkers_core:: {
275277 HttpMethod , HttpRequest , OperationsHandler , RequestBody ,
276278 } ;
@@ -279,17 +281,28 @@ async fn handle_worker_request(
279281 let storage_config_id = match & res. assets_storage_id {
280282 Some ( id) => id,
281283 None => {
282- return Ok ( error_response ( 500 , "ASSETS storage config not found" ) ) ;
284+ return Ok ( error_response_with_span (
285+ & span,
286+ 500 ,
287+ "ASSETS storage config not found" ,
288+ ) ) ;
283289 }
284290 } ;
285291
286292 // Load storage config
287293 let storage_config =
288294 openworkers_runner:: store:: get_storage_config ( conn, storage_config_id)
289295 . await ;
296+
290297 let storage_config = match storage_config {
291298 Some ( config) => config,
292- None => return Ok ( error_response ( 500 , "Storage config not found" ) ) ,
299+ None => {
300+ return Ok ( error_response_with_span (
301+ & span,
302+ 500 ,
303+ "Storage config not found" ,
304+ ) ) ;
305+ }
293306 } ;
294307
295308 // Create RunnerOperations with ASSETS binding to get limiters and stats
@@ -300,9 +313,24 @@ async fn handle_worker_request(
300313 } ,
301314 ] ) ;
302315
316+ // Transform path for prerendered routes (add .html extension)
317+ let request_path = if matches ! (
318+ res. asset_type,
319+ Some ( openworkers_runner:: store:: AssetType :: Prerendered )
320+ ) && !path. contains ( '.' )
321+ {
322+ if path == "/" || path. is_empty ( ) {
323+ "/index.html" . to_string ( )
324+ } else {
325+ format ! ( "{}.html" , path)
326+ }
327+ } else {
328+ path. to_string ( )
329+ } ;
330+
303331 // Create HttpRequest for binding fetch
304332 let http_request = HttpRequest {
305- url : path . to_string ( ) ,
333+ url : request_path ,
306334 method : HttpMethod :: Get ,
307335 headers : std:: collections:: HashMap :: new ( ) ,
308336 body : RequestBody :: None ,
@@ -331,8 +359,12 @@ async fn handle_worker_request(
331359 ) ;
332360
333361 error ! ( "Failed to fetch from storage: {}" , e) ;
334- span. record ( "response_status_code" , 404u16 ) ;
335- return Ok ( error_response ( 404 , "File not found" ) ) ;
362+ span. record ( "response_status_code" , 500u16 ) ;
363+ return Ok ( error_response_with_span (
364+ & span,
365+ 500 ,
366+ "Failed to fetch from storage" ,
367+ ) ) ;
336368 }
337369 }
338370 }
@@ -341,16 +373,18 @@ async fn handle_worker_request(
341373 // Standalone worker
342374 else if let Some ( worker_id) = res. worker_id {
343375 // Record backend type for standalone workers
344- span. record ( "backend_type" , "worker" ) ;
345- let worker = openworkers_runner:: store:: get_worker_with_bindings (
346- conn,
347- WorkerIdentifier :: Id ( worker_id) ,
348- )
349- . await ;
376+ span. record ( "backend_type" , tracing:: field:: display ( BackendType :: Worker ) ) ;
377+ let worker = get_worker_with_bindings ( conn, WorkerIdentifier :: Id ( worker_id) ) . await ;
350378
351379 match worker {
352380 Some ( w) => w,
353- None => return Ok ( error_response_with_span ( & span, 404 , "Worker not found" ) ) ,
381+ None => {
382+ return Ok ( error_response_with_span (
383+ & span,
384+ 500 ,
385+ "Route has worker_id but worker not found" ,
386+ ) ) ;
387+ }
354388 }
355389 } else {
356390 return Ok ( error_response_with_span (
@@ -363,8 +397,8 @@ async fn handle_worker_request(
363397 None => {
364398 return Ok ( error_response_with_span (
365399 & span,
366- 404 ,
367- "Endpoint or route not found" ,
400+ 502 ,
401+ "No worker or project found for request " ,
368402 ) ) ;
369403 }
370404 } ;
0 commit comments