Skip to content

Commit fbc31bc

Browse files
author
shuaishuai
committed
fix(workers): allow /v1/files preview without auth
1 parent 9fc08cc commit fbc31bc

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
9091
app.get("/v1/files/image/:imgPath{.+}", (c) =>
9192
c.redirect(`/images/${encodeURIComponent(c.req.param("imgPath"))}`, 302),
9293
);
9394
app.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+
97102
app.get("/_worker.js", (c) => c.notFound());
98103

99104
app.get("/", (c) => c.redirect("/login", 302));

0 commit comments

Comments
 (0)