This commit is contained in:
2023-08-30 16:19:25 +08:00
parent e831eee2cf
commit 75c2bf1c95
3 changed files with 28 additions and 35 deletions

View File

@@ -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;
}

View File

@@ -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);
}