@@ -81,19 +81,24 @@ app.onError((err, c) => {
8181 return withResponseHeaders ( res , { "x-grok2api-build" : buildSha } ) ;
8282} ) ;
8383
84- app . route ( "/v1" , openAiRoutes ) ;
85- app . route ( "/" , mediaRoutes ) ;
86- app . route ( "/" , adminRoutes ) ;
87-
8884// Backward-compatible local-cache viewer URLs used by the multi-page admin UI.
8985// In Workers we serve cache via /images/*, so redirect /v1/files/* to /images/*.
86+ //
87+ // IMPORTANT: define these routes BEFORE mounting `/v1` OpenAI routes.
88+ // Hono's `app.route("/v1", ...)` plus `use("/*", ...)` middleware would otherwise
89+ // intercept `/v1/files/*` and return 401 (no Authorization header) when users
90+ // click "view" in the admin cache page.
9091app . get ( "/v1/files/image/:imgPath{.+}" , ( c ) =>
9192 c . redirect ( `/images/${ encodeURIComponent ( c . req . param ( "imgPath" ) ) } ` , 302 ) ,
9293) ;
9394app . get ( "/v1/files/video/:imgPath{.+}" , ( c ) =>
9495 c . redirect ( `/images/${ encodeURIComponent ( c . req . param ( "imgPath" ) ) } ` , 302 ) ,
9596) ;
9697
98+ app . route ( "/v1" , openAiRoutes ) ;
99+ app . route ( "/" , mediaRoutes ) ;
100+ app . route ( "/" , adminRoutes ) ;
101+
97102app . get ( "/_worker.js" , ( c ) => c . notFound ( ) ) ;
98103
99104app . get ( "/" , ( c ) => c . redirect ( "/login" , 302 ) ) ;
0 commit comments