@@ -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,25 @@ async fn handle_worker_request(
300313 } ,
301314 ] ) ;
302315
316+ // Transform path for prerendered routes (add .html extension)
317+ // Static routes are stored with .html extension and don't need transformation
318+ let request_path = if matches ! (
319+ res. asset_type,
320+ Some ( openworkers_runner:: store:: AssetType :: Prerendered )
321+ ) && !path. contains ( '.' )
322+ {
323+ if path == "/" || path. is_empty ( ) {
324+ "/index.html" . to_string ( )
325+ } else {
326+ format ! ( "{}.html" , path)
327+ }
328+ } else {
329+ path. to_string ( )
330+ } ;
331+
303332 // Create HttpRequest for binding fetch
304333 let http_request = HttpRequest {
305- url : path . to_string ( ) ,
334+ url : request_path ,
306335 method : HttpMethod :: Get ,
307336 headers : std:: collections:: HashMap :: new ( ) ,
308337 body : RequestBody :: None ,
@@ -331,8 +360,12 @@ async fn handle_worker_request(
331360 ) ;
332361
333362 error ! ( "Failed to fetch from storage: {}" , e) ;
334- span. record ( "response_status_code" , 404u16 ) ;
335- return Ok ( error_response ( 404 , "File not found" ) ) ;
363+ span. record ( "response_status_code" , 500u16 ) ;
364+ return Ok ( error_response_with_span (
365+ & span,
366+ 500 ,
367+ "Failed to fetch from storage" ,
368+ ) ) ;
336369 }
337370 }
338371 }
@@ -341,16 +374,18 @@ async fn handle_worker_request(
341374 // Standalone worker
342375 else if let Some ( worker_id) = res. worker_id {
343376 // 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 ;
377+ span. record ( "backend_type" , tracing:: field:: display ( BackendType :: Worker ) ) ;
378+ let worker = get_worker_with_bindings ( conn, WorkerIdentifier :: Id ( worker_id) ) . await ;
350379
351380 match worker {
352381 Some ( w) => w,
353- None => return Ok ( error_response_with_span ( & span, 404 , "Worker not found" ) ) ,
382+ None => {
383+ return Ok ( error_response_with_span (
384+ & span,
385+ 500 ,
386+ "Route has worker_id but worker not found" ,
387+ ) ) ;
388+ }
354389 }
355390 } else {
356391 return Ok ( error_response_with_span (
@@ -363,8 +398,8 @@ async fn handle_worker_request(
363398 None => {
364399 return Ok ( error_response_with_span (
365400 & span,
366- 404 ,
367- "Endpoint or route not found" ,
401+ 502 ,
402+ "No worker or project found for request " ,
368403 ) ) ;
369404 }
370405 } ;
0 commit comments