Skip to content

Commit 8687a52

Browse files
authored
Refactor hono routes (#196)
* refactor hono routes * chore: deno fmt
1 parent 4d7c8d6 commit 8687a52

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/main.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hono } from "hono";
2-
import { routes } from "./routes/index.ts";
2+
import { companionRoutes, miscRoutes } from "./routes/index.ts";
33
import { Innertube } from "youtubei.js";
44
import { poTokenGenerate, type TokenMinter } from "./lib/jobs/potoken.ts";
55
import { USER_AGENT } from "bgutils";
@@ -11,7 +11,6 @@ import { existsSync } from "@std/fs/exists";
1111
import { parseConfig } from "./lib/helpers/config.ts";
1212
const config = await parseConfig();
1313
import { Metrics } from "./lib/helpers/metrics.ts";
14-
import health from "./routes/health.ts";
1514

1615
const args = parseArgs(Deno.args);
1716

@@ -138,9 +137,14 @@ companionApp.use("*", async (c, next) => {
138137
c.set("metrics", metrics);
139138
await next();
140139
});
141-
routes(companionApp, config);
140+
companionRoutes(companionApp, config);
141+
142+
app.use("*", async (c, next) => {
143+
c.set("metrics", metrics);
144+
await next();
145+
});
146+
miscRoutes(app, config);
142147

143-
app.route("/healthz", health);
144148
app.route("/", companionApp);
145149

146150
// This cannot be changed since companion restricts the

src/routes/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import getDownloadHandler from "./invidious_routes/download.ts";
1010
import videoPlaybackProxy from "./videoPlaybackProxy.ts";
1111
import type { Config } from "../lib/helpers/config.ts";
1212
import metrics from "./metrics.ts";
13+
import health from "./health.ts";
1314

14-
export const routes = (
15+
export const companionRoutes = (
1516
app: Hono,
1617
config: Config,
1718
) => {
@@ -40,6 +41,13 @@ export const routes = (
4041
app.route("/api/manifest/dash/id", invidiousRouteDashManifest);
4142
app.route("/api/v1/captions", invidiousCaptionsApi);
4243
app.route("/videoplayback", videoPlaybackProxy);
44+
};
45+
46+
export const miscRoutes = (
47+
app: Hono,
48+
config: Config,
49+
) => {
50+
app.route("/healthz", health);
4351
if (config.server.enable_metrics) {
4452
app.route("/metrics", metrics);
4553
}

0 commit comments

Comments
 (0)