This commit is contained in:
2023-08-30 16:08:34 +08:00
parent 0c98f8f5f8
commit e831eee2cf
3 changed files with 40 additions and 8 deletions

View File

@@ -0,0 +1,25 @@
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);
}