diff --git a/fresh.gen.ts b/fresh.gen.ts index ad3c604..a61cb3b 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -23,11 +23,10 @@ import * as $17 from "./routes/api/token.ts"; import * as $18 from "./routes/api/user.ts"; import * as $19 from "./routes/file/[id].ts"; import * as $20 from "./routes/file/_middleware.ts"; -import * as $21 from "./routes/flutter/_middleware.ts"; -import * as $22 from "./routes/index.tsx"; -import * as $23 from "./routes/manifest.json.ts"; -import * as $24 from "./routes/thumbnail/[id].ts"; -import * as $25 from "./routes/thumbnail/_middleware.ts"; +import * as $21 from "./routes/index.tsx"; +import * as $22 from "./routes/manifest.json.ts"; +import * as $23 from "./routes/thumbnail/[id].ts"; +import * as $24 from "./routes/thumbnail/_middleware.ts"; import * as $$0 from "./islands/Container.tsx"; import * as $$1 from "./islands/Settings.tsx"; import * as $$2 from "./islands/TaskManager.tsx"; @@ -55,11 +54,10 @@ const manifest = { "./routes/api/user.ts": $18, "./routes/file/[id].ts": $19, "./routes/file/_middleware.ts": $20, - "./routes/flutter/_middleware.ts": $21, - "./routes/index.tsx": $22, - "./routes/manifest.json.ts": $23, - "./routes/thumbnail/[id].ts": $24, - "./routes/thumbnail/_middleware.ts": $25, + "./routes/index.tsx": $21, + "./routes/manifest.json.ts": $22, + "./routes/thumbnail/[id].ts": $23, + "./routes/thumbnail/_middleware.ts": $24, }, islands: { "./islands/Container.tsx": $$0, diff --git a/routes/_middleware.ts b/routes/_middleware.ts index 700bac6..7ab72e3 100644 --- a/routes/_middleware.ts +++ b/routes/_middleware.ts @@ -6,6 +6,8 @@ import { get_file_response, GetFileResponseOptions, } from "../server/get_file_response.ts"; +import { exists } from "std/fs/exists.ts"; +import { get_task_manager } from "../server.ts"; const STATIC_FILES = ["/common.css", "/scrollBar.css", "/sw.js", "/sw.js.map"]; @@ -73,6 +75,24 @@ export async function handler(req: Request, ctx: MiddlewareHandlerContext) { } return get_file_response(file, opts); } + if (url.pathname == "/flutter" || url.pathname.startsWith("/flutter/")) { + const m = get_task_manager(); + if (!m.cfg.flutter_frontend) { + return new Response("Flutter frontend is not enabled", { + status: 404, + }); + } + const u = new URL(req.url); + let p = join(m.cfg.flutter_frontend, u.pathname.slice(8)); + if (!(await exists(p)) || p === m.cfg.flutter_frontend) { + p = join(m.cfg.flutter_frontend, "/index.html"); + } + const opts: GetFileResponseOptions = {}; + opts.range = req.headers.get("range"); + opts.if_modified_since = req.headers.get("If-Modified-Since"); + opts.if_unmodified_since = req.headers.get("If-Unmodified-Since"); + return await get_file_response(p, opts); + } const res = await ctx.next(); return res; } diff --git a/routes/flutter/_middleware.ts b/routes/flutter/_middleware.ts deleted file mode 100644 index 5ebb4ec..0000000 --- a/routes/flutter/_middleware.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { MiddlewareHandlerContext } from "$fresh/server.ts"; -import { get_task_manager } from "../../server.ts"; -import { join } from "std/path/mod.ts"; -import { exists } from "std/fs/exists.ts"; -import { - get_file_response, - GetFileResponseOptions, -} from "../../server/get_file_response.ts"; - -export async function handler(req: Request, _ctx: MiddlewareHandlerContext) { - const m = get_task_manager(); - if (!m.cfg.flutter_frontend) { - return new Response("Flutter frontend is not enabled", { status: 404 }); - } - const u = new URL(req.url); - let p = join(m.cfg.flutter_frontend, u.pathname); - if (!(await exists(p))) { - p = join(m.cfg.flutter_frontend, "/index.html"); - } - const opts: GetFileResponseOptions = {}; - opts.range = req.headers.get("range"); - opts.if_modified_since = req.headers.get("If-Modified-Since"); - opts.if_unmodified_since = req.headers.get("If-Unmodified-Since"); - return await get_file_response(p, opts); -}